websocket-sharp
websocket-sharp copied to clipboard
How to set sessionid?How to send point to point?
I want to achieve the kind of online customer service feature, you can chat one on one, I try to use sessions.sendto this method, but you can not set this sessionid, how can I do to find this ID? and How to combine the database
You should use the WebSocketService.ID
property and your own implementation with your WebSocketService
class and the WebSocket client.
For example, override WebSocketService.OnOpen
method, like the following:
protected override void OnOpen ()
{
Send ("Something list of sessions to the newer user");
Sessions.Broadcast (String.Format ("Something the newer user name and {0} to all", ID));
}
If someone sends a message from the client to the newer user and others,
ws.Send ("ID from the list of sessions or the newer users, and a message, in your format");
And then the server receives that message and use it with overridden WebSocketService.OnMessage
method, like the following:
protected override void OnMessage (MessageEventArgs e)
{
Sessions.SendTo ("ID from e.Data", "Content of message from e.Data");
}
I think that it becomes such a flow roughly.
e.Data doesn't contain ID, if use WebSocketService.ID, it seems to be a global variable, and when a large number of users send message to server, can it be able to get the ID of the sender accurately?
protected override void OnMessage (MessageEventArgs e) { Sessions.SendTo ("ID from e.Data", "Content of message from e.Data"); }
Does you know what is the uniqueness of the client that defines a different ID?