WebSocket handshake error: Unexpected response code: 500

I use websocket on my site, but by chance it sends me the following error message:

WebSocket connection with 'ws: //client.mydomain.com/socket.io/? EIO = 3 & transport = websocket & sid = 4Kbec5T_XStAC949AACS 'failed: WebSocket handshake error: unexpected response code: 500

This is how I connect to websocket in my application (note that this is an Angular application).

  app.factory('clientSocket', ['$sessionStorage', 'socketFactory', function ($sessionStorage, socketFactory) { var connection = ''; $.ajax({ url: 'config.json', async: false, dataType: 'json', success: function (response) { connection = response.app_url; } }); var myIoSocket = io.connect(connection); var clientSocket = socketFactory({ ioSocket: myIoSocket }); clientSocket.forward('someEvent'); clientSocket.on('connect', function () { if ($sessionStorage.activeUser != null) { clientSocket.emit('userData', $sessionStorage.activeUser.user); } }); return clientSocket; }]); 

I'm not quite sure what the problem is, but basically the connection string looks like this:

 http://client.mydomain.com 

Can someone tell me what is going on?

+5
source share
1 answer

Can't you try adding the rest of the code to the ajax callback? Like this:

 app.factory('clientSocket', ['$sessionStorage', 'socketFactory', function ($sessionStorage, socketFactory) { var connection = ''; $.ajax({ url: 'config.json', async: false, dataType: 'json', success: function (response) { connection = response.app_url; var myIoSocket = io.connect(connection); var clientSocket = socketFactory({ ioSocket: myIoSocket }); clientSocket.forward('someEvent'); clientSocket.on('connect', function () { if ($sessionStorage.activeUser != null) { clientSocket.emit('userData', $sessionStorage.activeUser.user); } }); return clientSocket; } }); 
0
source

Source: https://habr.com/ru/post/1235008/


All Articles