Sockjs Websocket

Asked

Viewed 69 times

1

I’m trying to use the Sockjs, and I put in the HEAD of my index the <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 on my console:

Uncaught Domexception: Failed to execute 'send' on 'Websocket': Still in CONNECTING state. (...)

And the mistake:

Websocket Connection to 'Ws://172.36.35.245/applications/index.html' failed: Error During Websocket Handshake: Unexpected Sponse code: 200

How do I connect with Websocket?

  • Have you solved your problem? The same is happening to me :/

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.