websocket-sharp icon indicating copy to clipboard operation
websocket-sharp copied to clipboard

How to set sessionid?How to send point to point?

Open mou18 opened this issue 10 years ago • 3 comments

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

mou18 avatar Aug 26 '14 02:08 mou18

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.

sta avatar Aug 27 '14 06:08 sta

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"); }

xm9572 avatar Dec 30 '17 13:12 xm9572

Does you know what is the uniqueness of the client that defines a different ID?

Reli-AS avatar Dec 22 '21 10:12 Reli-AS