2

I have a simple chat app written with WebSocket-Sharp. Each of the clients has a unique ID (UID-<6 random numbers 0-9>-@)

My question is if one of the clients disconnects, then how do I know which one of them disconnected? Like I have a List ConnectedClients which contains all of the unique IDs and I want to update that list... how can I do that? Any help would be appreciated.

JRKGaming
  • 31
  • 1
  • A socket don't know when the other side is disconnect except when an error occur or you call disconnect. You can add some message as a ping message and both sides (server and client) do a ping every X time elapsed. If the other side don't respond or you get an error, you can assume that connection is broken. As an optimization, you can check your normal messages and don't send ping message if you get messages from the other side. Only after some time without any message from the other side, you check if all is ok sending a ping message – Victor Apr 22 '22 at 00:18

0 Answers0