Tech Off Post

Single Post Permalink

View Thread: TcpClient - Test for Disconnected?
  • User profile image

    phreaks said:
    cheong said:
    Nah, I am getting data all the time, lapse of perhaps 5-6 seconds max during slow periods, otherwise I am constantly receiveing data.

    I don't think it's benificial to keep opening / closing sockets in this scenario.

    No. I mean you should implement your sending function this way.

    1. Send the data using existing connection, catch your exception.
    2. If it is SocketException and the ErrorCode is OPERATION_ABORTED, ENETRESET or others indicating disconnect condition, reopen the client and attempt to resend it. Retry up to 3 times or any theshold you desire.

    I didn't write it anywhere for you to keep closing/opening sockets. Just do what MSDN documentation suggest you to do - send data to determine whether it's closed.