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
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
^ explicitly handle kicking, otherwise the client won't be able to differentiate it from a connection timeout
Heartbeat is the best way to check whether a client has been disconnected, ie computer crash, etc.
Thank you all for the methods, sorry for not replying earlier