Trying to connect to SockJs server.  I am running the following code from a secure https page https://localhost/index.php
    var sockjs_url = 'http://localhost:9999/echo';
    var sockjs = new SockJS(sockjs_url);
    sockjs.onopen    = function()  {console.log('[*] open' + sockjs.protocol);};
    sockjs.onmessage = function(e) {console.log('[.] message' + e.data);};
    sockjs.onclose   = function()  {console.log('[*] close');};
I get SecurityError: The operation is insecure. and it falls back to openxhr-polling
If I run it from http http://localhost/index.php websocket connection is established.
Is it not possible to create an unsecure websocket from a secure page?
UPDATE This happens in Firefox but in Chrome I'm able to open websocket
UPDATE 2 Eventually I resolved it by using a https server. See here.
UPDATE 3 Related Firefox Websocket security issue
 
     
    