Jump to content

Recommended Posts

Posted

Yes but the previous error which is always occurring in Firefox Console "Firefox can’t establish a connection to the server at wss://192.168.1.201/ws/." But this time another error was occurred "500 Proxy Error" and the "SSL_ERROR_RX_RECORD_TOO_LONG" error has gone but the WSS request is going through HTTPS instead of WSS. I've changed my client.js after setting up proxy. Here is the new one:

var colors = [
	'#007AFF','#FF7000','#FF7000','#15E25F','#CFC700','#CFC700','#CF1100','#CF00BE','#F00'
];
var color_pick = Math.floor(Math.random() * colors.length);

//create a new WebSocket object.
var msgBox = $('#message-box');
//var wsUri = "wss://localhost/ws/";
var wsUri = "wss://192.168.1.201/ws/";
//var wsUri = "wss://192.168.1.201:9000/server.php";
websocket = new WebSocket(wsUri);

websocket.readyStateChange = function (e) { // connection is open 
	console.log(e);
}

websocket.onopen = function (ev) { // connection is open 
	msgBox.append('<div class="system_msg" style="color:#bbbbbb">Welcome to my "Demo WebSocket Chat box"!</div>'); //notify user
}
// Message received from server
websocket.onmessage = function (ev) {
	var response = JSON.parse(ev.data); //PHP sends Json data

	
	
	var res_type = response.type; //message type
	var user_message = response.message; //message text
	var user_name = response.name; //user name
	var user_color = response.color; //color

console.log(res_type);
	switch (res_type) {
		case 'usermsg':
			if($("#user_typing").length > 0)
				$("#user_typing").remove();
			msgBox.append('<div><span class="user_name" style="color:' + user_color + '">' + user_name + '</span> : <span class="user_msg">' + user_message + '</span></div>');
			break;
		case 'system':
			msgBox.append('<div style="color:#bbbbbb">' + user_message + '</div>');
			break;
		case 'notification':
			var user_notification = response.notification; //notification type
			if(user_notification === 'typing'){
				if($("#user_typing").length <= 0)
					msgBox.append('<div id="user_typing"><span class="user_name" style="color:' + user_color + '">' + user_name + '</span> : <span class="system_msg">' + user_message + '</span></div>');
			} else
				msgBox.append('<div id="user_notification"><span class="user_name" style="color:' + user_color + '">' + user_name + '</span> : <span class="system_msg">' + user_message + '</span></div>');
			break;
	}
	msgBox[0].scrollTop = msgBox[0].scrollHeight; //scroll message 

};

websocket.onerror = function (e) {
	msgBox.append('<div class="system_error">Error Occurred - ' + e.data + '</div>');
};
websocket.onclose = function (e) {
	if(e.wasClean)
		msgBox.append('<div class="system_msg">Connection Closed</div>');
	else
		msgBox.append('<div class="system_error">Connection Interrupted - [Error#' + e.code + '] ' + e.reason + '</div>');
};

//Message send button
$('#send-message').click(function () {
	send_message();
});

//User hits enter key 
$("#message").on("keydown", function (event) {
	if (event.which == 13) {
		send_message();
	}
});
//User typing
$("#message").on("keypress", function (event) {
	if (event.which !== 13)
		send_notification('typing','Typing...');
});

var notifications = [], isTyping = false;

//Send message
function send_message() {
	var message_input = $('#message'); //user message text
	var name_input = $('#name'); //user name

	if (message_input.val() == "") { //empty name?
		alert("Enter your Name please!");
		return;
	}
	if (message_input.val() == "") { //emtpy message?
		alert("Enter Some message Please!");
		return;
	}
	
	isTyping = false;

	//prepare json data
	var msg = {
		message: message_input.val(),
		name: name_input.val(),
		color: colors[color_pick]
	};
	//convert and send data to server
	websocket.send(JSON.stringify(msg));
	message_input.val(''); //reset message input
}

//Send message
function send_notification(type, msg) {
	var name_input = $('#name'); //user name
	notifications.push(type);
	//prepare json data
	var msg = {
		notification: type,
		message: msg,
		name: name_input.val(),
		color: colors[color_pick]
	};
	if(!isTyping){
		isTyping = true;
		//convert and send data to server
		websocket.send(JSON.stringify(msg));
	}
}
Here is the Virtual Host configuration:


<VirtualHost _default_:443>
	SSLEngine on
	ServerName localhost:443
	SSLCertificateFile "${SRVROOT}/conf/ssl/localhost.crt"
	SSLCertificateKeyFile "${SRVROOT}/conf/ssl/localhost.pem"
	DocumentRoot "${SRVROOT}/htdocs"
	# DocumentRoot access handled globally in httpd.conf
	CustomLog "${SRVROOT}/logs/ssl_request.log" \"%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
	<Directory "${SRVROOT}/htdocs">
		Options Indexes Includes FollowSymLinks
		AllowOverride AuthConfig Limit FileInfo
		Require all granted
	</Directory>
	SSLProxyEngine on
	ProxyPass /ws/ wss://localhost:9000
	ProxyPassReverse /ws/ wss://localhost:9000
	ProxyRequests off
</VirtualHost>

<VirtualHost 192.168.1.201:443>
	DocumentRoot "${SRVROOT}/htdocs"
	ServerName 192.168.1.201
	SSLEngine on
	#SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
	SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA
	SSLCertificateFile "${SRVROOT}/conf/ssl/localhost.crt"
	SSLCertificateKeyFile "${SRVROOT}/conf/ssl/localhost.pem"
	SSLCertificateChainFile "${SRVROOT}/conf/ssl/ca-chain.pem"
	SSLProxyEngine on
	ProxyPass /ws/ wss://192.168.1.201:9000
	ProxyPassReverse /ws/ wss://192.168.1.201:9000
	ProxyRequests off
	ErrorLog "${SRVROOT}/logs/error.log"
	CustomLog "${SRVROOT}/logs/access.log" common
	LogLevel warn
</VirtualHost>
Posted

Okay, so finally I've solved the problem. What I did is, changed the virtual-ssl-host configuration and httpd.conf. Here is the new configurations:

 

httpd-ahssl.conf/httpd-ssl.conf:

<VirtualHost _default_:443>
	SSLEngine on
	ServerName localhost:443
	SSLCertificateFile "${SRVROOT}/conf/ssl/localhost.crt"
	SSLCertificateKeyFile "${SRVROOT}/conf/ssl/localhost.pem"
	DocumentRoot "${SRVROOT}/htdocs"
	# DocumentRoot access handled globally in httpd.conf
	CustomLog "${SRVROOT}/logs/ssl_request.log" \
          "%t %h %{SSL_PROTOCOL}x %{SSL_CIPHER}x \"%r\" %b"
	<Directory "${SRVROOT}/htdocs">
		Options Indexes Includes FollowSymLinks
		AllowOverride AuthConfig Limit FileInfo
		Require all granted
	</Directory>
	SSLProxyEngine on
	ProxyPass /ws/ ws://localhost:9000
	ProxyPassReverse /ws/ ws://localhost:9000
	ProxyRequests off
</VirtualHost>

<VirtualHost 192.168.1.201:443>
	DocumentRoot "${SRVROOT}/htdocs"
	ServerName 192.168.1.201
	SSLEngine on
	#SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
	SSLCipherSuite ECDHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:DHE-RSA-AES128-SHA
	SSLCertificateFile "${SRVROOT}/conf/ssl/localhost.crt"
	SSLCertificateKeyFile "${SRVROOT}/conf/ssl/localhost.pem"
	SSLCertificateChainFile "${SRVROOT}/conf/ssl/ca-chain.pem"
	#SSLProxyCACertificateFile "${SRVROOT}/conf/ssl/localhost.crt"
	SSLProxyEngine on
	#SSLProxyVerify none
	#SSLProxyCheckPeerCN off
	#SSLProxyCheckPeerName off
	ProxyPass /ws/ ws://192.168.1.201:9000
	ProxyPassReverse /ws/ ws://192.168.1.201:9000
	ProxyRequests off
	ErrorLog "${SRVROOT}/logs/error.log"
	CustomLog "${SRVROOT}/logs/access.log" common
	LogLevel warn
</VirtualHost>

httpd.conf: (here I've just loaded almost all the modules related to mod_proxy)

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_express_module modules/mod_proxy_express.so
LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
#LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
#LoadModule proxy_html_module modules/mod_proxy_html.so
LoadModule proxy_hcheck_module modules/mod_proxy_hcheck.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_http2_module modules/mod_proxy_http2.so
LoadModule proxy_scgi_module modules/mod_proxy_scgi.so
LoadModule proxy_wstunnel_module modules/mod_proxy_wstunnel.so
LoadModule watchdog_module modules/mod_watchdog.so
Thank you Krydos & wolstech sir for helping me out.

 

 

Now another question, you can see all the configurations I have, can I host the application in Heliohost?

Posted

Is there any ways to host this on Tommy server?

  • 1 year later...
Posted

Hi, I have the same problem... it seems that socket_create can not work with ssl certificate (stream_socket_server can) did you manage to sort it out?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...