ambelovsky / gosf

Go SocketIO API Framework

Home Page:http://gosf.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Question] Sending messages to a particular client?

unm4sk1g opened this issue · comments

Hello,

I'm wondering is it possible to send messages directly to a particular client without joining him into a room? I see that Client struct has no ID or anything, so I have no idea if you differentiate clients by anything?

Thanks in advance.

Hi!

You can respond directly to the client sending a request without joining them to a room. Take a look at the "Request/Response Cycle" documentation on gosf.io. There are code samples there to get you started.

Currently, sifting through an array of connection IDs and sending to one of them separately is not possible. If you have clients stored by random connection ID, it really doesn't help you differentiate among users, because the random ID does not represent an individual user's identity or purpose. It only represents one of potentially many of that user's connections.

Best practice is to join the user to a room based on a more meaningful identifier whenever you can.

If a user logs into the system by sending their username/password through the standard request/response cycle, then you can join them to a room based on their username or user ID. You can then broadcast that user's updates to the room setup for their username or user ID.

This is useful, because a user may have multiple connections. If a user is connected through a mobile app and a website with the same username, updates for that user should generally be pushed to both their mobile app and their website connection if they are utilizing the same API, connection, and authentication parameters.

I do intend to integrate connection ID information and session management in a future release. For now, double-check your use-case to be sure it doesn't fit within the standard request/response cycle or room scenarios.

If you have more information on your reason for needing to send messages by connection ID, please reach back out to let me know. I'm interested to hear more use-cases for this.

Hi,

sorry for late response, was on long awaited holiday. Will check our use case again, maybe the room way is okay at the end.

Thanks again, and great work on the library so far :)