M
M
mopsicus2016-10-26 20:01:00
Node.js
mopsicus, 2016-10-26 20:01:00

How to overwrite a socket in nodejs?

I started to learn nodejs, I'm making a simple game server and I want to implement a reconnect to the game.

There is an array with players players, when a new player is connected, I write its socket to the player players[i].connection = socket so that later it would be easy to send messages to everyone. When disconnecting, I do not remove the player from the array, but simply set the status to disabled. When reconnecting, I save a new socket for the player players[i].connection = socket, but after that, if I try to send something players[i].connection.write(...) does not work.

What am I doing wrong? Maybe you need to somehow close / delete the previous socket?

Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SagePtr, 2016-10-26
@mopsicus

Видимо, в каком-то месте работаете с копией массива, а не с оригинальным, либо с копией players[i].connection.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question