user1328830
user1328830

Reputation: 153

Socket.io client behavior when server is unreachable

I was wondering what is the default behavior when socket.io-client can't connect to the server and no callback is provided on the error.

Does the client indefinitely try to reconnect until it can reach the server?

I noticed that If I run this code on client before launching the server. As soon as the latter is started it receives the 'doSomethig' evnt.

socket.on('connect', function () {
    socket.emit('doSomething', data);
    socket.destroy();
});

How can I prevent the server to receive data emitted before it was started?

Upvotes: 0

Views: 380

Answers (1)

user1328830
user1328830

Reputation: 153

socket.on('connect_error', function () { socket.destroy(); });

Upvotes: 3

Related Questions