TCPListener - Client Disconnect

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • =?Utf-8?B?SGl3ag==?=

    #1

    TCPListener - Client Disconnect

    I recently upgraded my application from VB6, and was using the Winsock
    control. In VB2005 I am using the TcpListener Class and have managed to get
    it working, except for one thing:

    Is there a way for the server to detect when a client disconnects (i.e.
    closes the program abruptly)? In VB6 the Winsock control had the Close event,
    which would fire when the client disconnected.

    Some suggest that it can be done by sending a message to the client at
    regular intervals (heartbeat) to check for connectivity, but I would rather
    not have to do this.

    Is there a method for when the client disconnects?

  • Armin Zingler

    #2
    Re: TCPListener - Client Disconnect

    "Hiwj" <Hiwj@discussio ns.microsoft.co mschrieb
    I recently upgraded my application from VB6, and was using the
    Winsock control. In VB2005 I am using the TcpListener Class and have
    managed to get it working, except for one thing:
    >
    Is there a way for the server to detect when a client disconnects
    (i.e. closes the program abruptly)? In VB6 the Winsock control had
    the Close event, which would fire when the client disconnected.
    >
    Some suggest that it can be done by sending a message to the client
    at regular intervals (heartbeat) to check for connectivity, but I
    would rather not have to do this.
    >
    Is there a method for when the client disconnects?


    An event? I don't think so. More:





    Armin

    Comment

    • =?Utf-8?B?aXdkdTE1?=

      #3
      RE: TCPListener - Client Disconnect

      when a client disconnects, the number of bytes sent is 0....for example

      private sub BytesReceived(B yVal ar As IAsycResult)

      Dim numBytes as integer = ClientSocket.En dReceive(ar

      if numBytes = 0

      ''close connection, client disconnected

      ....

      end sub


      in the method where you receive information, create a check like that and
      you will be notified when a client disconnects

      hope this helps

      --
      -iwdu15

      Comment

      • Sean

        #4
        C++ client disconnection

        Ok, but what if the client does not send a constant stream data to the server? - such as in the case of a client command prompt? How then can you tell when the client disconnects?

        EggHeadCafe.com - .NET Developer Portal of Choice

        Comment

        • =?Utf-8?B?aXdkdTE1?=

          #5
          RE: C++ client disconnection

          since its a TCP connection, you dont have to worry about a constant stream of
          bytes. whenever the connection is broken, the Received method will be called
          with the number of bytes being 0. thats how you can tell if the client
          disconnects
          --
          -iwdu15

          Comment

          Working...