Socket.io connection to server sometimes does not work

I have a Node.JS server installed with socket.io on VPS , and every 10 seconds I transfer the number of connected clients to all. This usually works fine, although it often happens, the connection cannot be established, and I get this error (I changed the IP a bit):

GET http://166.0.0.55:8177/socket.io/1/?t=1385120872574

After reloading the site, as a rule, the connection can be established, although I have no idea why the connection failed in the first place, I also don’t know how to debug socket.io code. Sometimes I can no longer connect to the server, and I need to restart the server.

Additional Information:

  • My main site runs on a different server (using the LAMP environment with CakePHP) than the Node.js. server
  • I use forever to start the server
  • I have many connected clients (about 1000).
  • My VPS has 512 MB RAM and the processor never exceeds 25%
+4
source share
1 answer

After the top command try:

socket.on('error', function (err) { 
   console.log("Socket.IO Error"); 
   console.log(err.stack); // this is changed from your code in last comment
});

Alternatively, you can try slower transport. Socket.io uses Websocket by default, but if your server cannot allocate sufficient resources, you can try another transport, which is slower but uses less resources.

io = socketIo.listen(80);
io.set('transports', ['xhr-polling']);
+3
source

All Articles