Doubts about the operation of the socket.io

4

I have a doubt regarding the socket.io that I have researched in several places and most of the one rolled or uses obscure terms, but ends up not answering the doubt directly.

The question is whether it works in the following way: at the time of the server sending a message to the user it accidentally registers the "address" of the user in some way and then sends the communication directly to this address without the user needing do no request (ajax or direct)? And can my server have multiple "registered" users each receiving messages only from another specific user?

    
asked by anonymous 19.11.2015 / 02:49

1 answer

4

Yes.

Socket.io does nothing more than abstract a websocket connection for you.

The socket connection is between the user and the server, so to accomplish what you will need to perform some type of login, even if it is just a nick (in a chat example) so that you can associate the nick with a socket.

You will get a map of nicks / logins pointing to your socket.

When you want to create a channel enter user A and B the following scenario will happen:

A sends data to the server. Server receives the data. Server handles the data (if necessary) Server forwards data to B.

On receiving messages from a specific user, at the time of processing via server you can choose to re-send the data to user B or not, that is, this control is the responsibility of the programmer.

You already have some functional code to test, maybe I can help you implement what you need / want to do.

    
19.11.2015 / 04:04