Как обнаружить отключение клиента от сервера с помощью tcpclient
I have two separate applications Client and Server used to send and receive data from Ethernet Cable. The Client application sends the data to server. First when the server application is started, it starts accepting client request to accept data. As soon as client is connected , Server thread is started to receive data from Client. Whenever Client application is stopped, there must be either some command send to the server to notify that it has disconnected or there must be some way to detect client disconnection at server end so that thread can be closed for receiving data from Client. I am using TCPClient for this purpose. Kindly suggest some way to do this.
Спасибо
Что я уже пробовал:
я пытаюсь отключить клиента от сервера, но сервер все равно видит, что он подключен.
Rob Philpott
Хорошо, это не авторский ответ, так как я не совсем уверен, но я думаю, что если у вас есть TcpClient на стороне сервера, и предположительно у вас есть поток от него, из которого Вы читаете то, что клиент посылает вам.
Чтение из потока синхронно блокируется, пока не будут получены байты. В случае отключения вызов разблокируется, но вы не прочитаете ни одного байта.
Я *думаю*, что вы можете использовать это, после чего вы должны сделать цикл закрытия/выключения.