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
javascript jquery ssl websocket stunnel
Mike a
source share