C
C#3y ago
koopa

Disconnect a client from a TCPServer csharp

Hi - I have a basic client server chat room model which I'm working on for a school project. I'm trying to program a /kick feature to disconnect a client from the server, however TCPClient.Close() and TCPClient.Client.Disconnect() do not seem to be working - as in the client thinks that it is still connected, not sure whether I just need to update the client that it is not connected or whether I should use a different disconnect method.
4 Replies
Anchy
Anchy3y ago
you can send some data to the server to check to see if the socket is still open what i did on my simple tcp client/server was to send a disconnect packet to the client before kicking it then the client receives that packet and handles the disconnect gracefully
Up
Up3y ago
^ explicitly handle kicking, otherwise the client won't be able to differentiate it from a connection timeout
Buddy
Buddy3y ago
Heartbeat is the best way to check whether a client has been disconnected, ie computer crash, etc.
koopa
koopaOP3y ago
Thank you all for the methods, sorry for not replying earlier

Did you find this page helpful?