Results 1 to 6 of 6

Thread: detectc client disconnect

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Location
    india
    Posts
    18

    Smile detectc client disconnect

    helo guys
    i wrote a program (vb.net2005) for client- server communications using tcp/ip ,all are workin pretty well except one thing . when ever one new client is conected to server i ll display client ip and machine name on a grid. but i wont able to detect when a client is disconnected from a server

    please provide some sample code for this

    thx

  2. #2
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: detectc client disconnect

    You need to test whether the socket is still connected, then cleanup from there.

    Do you know how to make custom events?

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Location
    india
    Posts
    18

    Smile Re: detectc client disconnect

    no campion,
    i dont no how to make custom events can u help me out
    pls and also pls specify some sample codes

    tahnx

  4. #4
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: detectc client disconnect

    I need a little more information, as well. Are you using an object to encapsulate the connections, or are they just being handled by a form?

    Is each connection handled inside of its own class?

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2009
    Location
    india
    Posts
    18

    Smile Re: detectc client disconnect

    yep it is just handled by a form . i had one client module and server module
    to handle connections

  6. #6
    Frenzied Member Campion's Avatar
    Join Date
    Jul 2007
    Location
    UT
    Posts
    1,098

    Re: detectc client disconnect

    This is how I handle disconnections. There's an event in there that fires off when it is sensed that the socket is no longer connected. However, since you have everything self-contained onto a form, what you need to do instead is ensure that your sockets are closed and that any references to the client no longer exists anywhere else in your project.

    Code:
    Try
                BytesRead = _TcpServer.GetStream.EndRead(Ar)
    
                _ServerMsgBuild = Encoding.GetEncoding(1252).GetString(_ServerBuffer, 0, BytesRead)
    
    
                While _TcpServer.GetStream.DataAvailable
                    _ServerMsgBuild +=  Encoding.GetEncoding(1252).GetString(_ServerBuffer, 0,  _
                         _TcpServer.GetStream.Read(_ServerBuffer, 0, _ServerBuffer.Length))
                End While
            Catch ex As Exception
                RaiseEvent Disconnected()
                Return
            End Try

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width