Answer the question
In order to leave comments, you need to log in
How to bind the server with the client in case of connection failures so that the client does not interrupt the game process?
Hello!
I am writing a multiplayer game (client/server). Socket.io + Node.JS
I asked myself this question, how to more competently bind the server with the client in case of connection failures, so that the client does not interrupt the game process? At first I thought about binding to socket.id, but it changes to another one when reconnecting. Then I thought to make a binding according to the client's login, but the game will be without registration and, therefore, without passwords, i.e. it is possible to have players with the same logins (names) in the game. After thinking more, I decided to make a client connect event, give it a unique ID, but when the connection is broken, reconnect is triggered and the connect event is called again, at which, again, the server will give it a different ID different from the previous one and again we lose the client.
Answer the question
In order to leave comments, you need to log in
Generate your own ID on the server, for example in the form of a GUID (then you won’t even need to worry about uniqueness), pass it to the client and save it in a cookie and in localstorage, when breaking and restoring, pass the ID to the server and restore the session.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question