SockJS WebSocket

1

I'm trying to use SockJS, and I put in the HEAD of my index <script src="//cdn.jsdelivr.net/sockjs/1/sockjs.min.js"></script> and javascript:

var wsUrl = 'ws://' + window.location.host 
var ws = new WebSocket(wsUrl + '/aplicacoes/index.html')

ws.onopen = function () {
    console.log('open');
};
ws.onmessage = function (e) {
    console.log('message', e.data);
};
ws.onclose = function () {
    console.log('close');
};

ws.send('test');
ws.close();

And 2 errors appear in my console:

  Uncaught DOMException: Failed to execute 'send' on 'WebSocket': Still in CONNECTING state. (...)

And the error:

  

WebSocket connection to 'ws: //172.36.35.245/applications/index.html' failed: Error during WebSocket handshake: Unexpected response code: 200

How do I connect to WebSocket?

    
asked by anonymous 07.11.2016 / 18:44

0 answers