Click here to Skip to main content
16,006,001 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
See more:
Hello,

I am using TCPClient for only for reading data from EndPoint. How to detect the remote end point is disconnected, so that reconnect can be executed.

Naina

What I have tried:

This we have tried poll, available using socket, but how to detect disconnection for TCPClient.
Posted
Updated 28-Apr-16 15:07pm

Hi, Just Ping the server from code, and check the results, if you got response your connection is not broken, else you have disconnected. Check this links to know more.
 
Share this answer
 
Don't. Assume it is connected. Just perform your network I/O according to your application-layer protocol, that is, send and receive data, and, if it fails, handle the exception. For more detail on that, please see my past answers:
http://www.codeproject.com/Answers/848979/How-Do-I-Get-To-Know-If-A-A-Tcp-Connection-Is-Over#answer1[^],
an amateur question in socket programming[^],
Multple clients from same port Number[^].

By the way, please don't tell me that you don't have such application-level protocol. It would simply mean that you have it implicitly, somehow assuming what is should do. But it's always better to realize it and develop a comprehensive definition of your protocol. Please see: Application layer — Wikipedia, the free encyclopedia[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900