R
R
root092016-09-13 07:28:05
Node.js
root09, 2016-09-13 07:28:05

Why takes a long time to connect to socket io nodejs?

Online:

var socket = io("http://ip:port/");

socket.on('connect', function(data){
  console.log('Connected to server!');
});

in nodejs:
io.sockets.on('connection', function (socket) {
       online++;	
  socket.on('disconnect', function(){
          online--;
  });
});

The problem is that when a person visits the site, the line "console.log('Connected to server!');" sometimes it works right away, and sometimes after 3-4 seconds, the same thing happens if you just go to the address " http://ip:port/ ", sometimes it's an empty page, and sometimes it loads a few seconds first ...
What could be the problem ? where does the delay come from? VDS on Ubuntu 14

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question