So when I start the js socket on the website I am receiving this error:
and after some errors of 'websocket is closed ....' the website will finally connect without errors, but if I refresh again, then I need to wait for 4-5 or 10 errors until it successfully connect.
Any solutions, please?
I'm using this code for socket server:
var server = require('http').createServer();
var io = require('socket.io')(server);
server.listen(3001);
Frontend code:
function connect()
{
if (!SOCKET)
{
var hash = getCookie('hash');
SOCKET = io('IP:3001');
SOCKET.on('connect', function(msg) {
SOCKET.emit('hash', {
hash: hash
});
});
SOCKET.on('connect_error', function(msg) {
$.notify('Connection lost!', 'success');
});
SOCKET.on('message', function(msg) {
onMessage(msg);
});
SOCKET.on('disconnect', function() {
});
}
else
{
console.log("Error: connection already exists.");
}
}