Question

I'm using Node.js with socket.io for a multiplayer game. There are game rooms and players can join different rooms. That part works fine.

Now, I want to be prepared for the possibility of the Node server crashing for whatever reason. I have Node backing up data to Redis, and if it crashes, it restarts automatically, fetches the data back from Redis and continues normal operation.

That's what I want anyway, but I'm confused about one thing. Since each socket is identified by its ID, how can the server know which user to subscribe to which room after a restart? Will the socket IDs still be valid? Or do they need to be re-assigned somehow (presumably based on unique user IDs)?

Was it helpful?

Solution

To be honest I have never worked with socket.io, but I have worked with sockjs. I don't know what are the implementation differences, but sockjs also has each connection identified by its own ID (which is a UUID, as far as I see it). But the ID changes every time a user reconnects, so I believe it is not a useful way to identify users.

Maybe you should store some fixed user identification (such as email address, username) and relocate the user by that parameter (that's what I'm doing usually).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top