Failed to connect to websocket

I created a PHP website using Ratchet . This website runs on port 8080 my internal server 10.0.4.160 .

I try to connect to it from a website that has SSL enabled, the so-called https protocol.

When I try to connect to websocket using the FireFox browser, I get security problems from the browser because I mix between a secure / insecure connection. This is the error that I see in the javascript console.

SecurityError: operation is unsafe.

To fix the security problem, I created a stunnel proxy that allows me to accept the connection on 10.0.4.160:58443 and connect it to port 127.0.0.1:8080 . This secure tunnel should allow me to maintain my connection to a secure website and bypass the browser security check.

However, every time I try to connect to websocket, I get an error

Connection to WebSocket with 'wss: //10.0.4.160: 58443 /' failed: connection error: net :: ERR_TIMED_OUT

This is a jQuery script that is used to connect to websocket

 <script> $(function(){ if ("WebSocket" in window) { var conn = new WebSocket('wss://10.0.4.160:58443'); conn.onopen = function(e) { console.log("Connection established!"); showMessage('Connected', 0); }; conn.onmessage = function(e) { console.log(e.data); showMessage(e.data, 1); }; conn.onclose = function(e) { console.log(e.code); console.log(e.reason); }; conn.onerror = function(e) { console.log(e); }; } else { console.log('Your browser does not support Websocket!'); } function showMessage(msg, append){ if(append){ $('#status').append('<br>' + msg); return; } $('#status').text(msg); } }); </script> 

Here is my current stunnel configuration

 [websockets] client = yes accept = 58443 connect = 8080 verify = 2 CAfile = ca-certs.pem debug = 7 OCSPaia = yes 

How to connect to websocket from my browser? Thanks you

+7
javascript jquery ssl websocket stunnel
source share
1 answer

Learn more about html5 websockets at http://www.html5rocks.com/en/tutorials/websockets/basics/

Socket.io is a popular network socket library, read more at www.socket.io

There is not enough information to diagnose your problem. Specify the server log.

  • Does your server recognize a connection attempt?
  • Does your server handle the handshake of a client server?

If your server recognizes a connection attempt, your problem will most likely be a handshake. There is no problem in your JavaScript.


ADDITIONAL INFORMATION:

another type of connection: (we will call this type 1)

 |SERVER(PHP)| <--- CONNECTION --> |SERVER(websocket)| 

what you use: (we will call this type 2)

 |BROWSER(client)| <----CONNECTION --> |SERVER(websocket)| 

when using type 1 connections as type 2 connections that you run the risk of crowding your main web server, which can lead to serious performance problems. A web host like: Godaddy, Hostgator .. ect .. will terminate the connections that flood their servers because they are seen as DDOS attacks.

I don’t know what ratchet is, but in order to maintain a connection to the server and the client, PHP must remain open, and NEVER NEVER NEVER, NEVER would ever be a good idea. Examine the created server in languages ​​such as C # or C ++.

+1
source share

All Articles