josh
josh

Reputation: 145

socket.io reconnect does not work as expected

Whenever a player logouts in my game, the server disconnects the client; however, when the player tries to login again after already being disconnected, the client tries to renew the connection -- upon a successful reconnect, I execute a callback function. I do this by using the Socket.IO function

client.io.reconnect();

The server successfully shows that a new connection was made, but the client still seems to be totally disconnected. Why is this?

Summary: server disconnects client. I can't get client to successfully reconnect and fire the client.on('connect') event.

Upvotes: 0

Views: 449

Answers (1)

Andrey Popov
Andrey Popov

Reputation: 7510

The client side is made so if it's forced to disconnect, it cannot reconnect. You can see it in the code here and here:

// socket.js
/**
 * Called upon forced client/server side disconnections,
 * this method ensures the manager stops tracking us and
 * that reconnections don't get triggered for this.
 *
 * @api private.
 */

// manager.js

Manager.prototype.reconnect = function(){
  if (this.reconnecting || this.skipReconnect) return this;

If you are afraid you will lose your listeners, then introduce a function to add those listeners and add them when needed :)

Upvotes: 1

Related Questions