Let's say I have a tcp server in nodejs and two clients connected (socket1 and socket2). So, when a data event is received from one, I want to write that to the other. As simple as that. The easiest would be to store socket1 in socket2 and vice versa. For example:
socket1.other=socket2;
socket2.other=socket1;
So, when
socket1 sends data to server I can simply: socket1.other.write
the data, but in that case socket1
would store a reference to socket2
which includes socket1
and this does not seem to work.
Is the only way to store both in an array and always loop through it to find the other socket when data needs to be sent?