Results 1 to 4 of 4

Thread: checking wsock connection when improperly shutdown

  1. #1

    Thread Starter
    Addicted Member bulletrick's Avatar
    Join Date
    Jul 2005
    Location
    Philippines
    Posts
    248

    Question checking wsock connection when improperly shutdown

    My form sends a winsock.close message when a pc is properly shut down.

    but when a pc is improperly shut down (accidentally unplugged), my form will not have the chance to send a winsock.close message thus the server detects the improperly shutdown client as still online.

    what should i do in the server for me to detect the connection if the client is improperly shutdown?

    i tried using checking the sckServer.State but the state in the server is still sckConnected.

    Please help guys! Thanks!

  2. #2
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: checking wsock connection when improperly shutdown

    the best way to do this is to send out a ping to all the clients, this will determine accuratley if users online list.

    so just have your server send out a packet, it could even just send "PING" and the client must send it back when it receives it, its simple code for your data arrival sub

    if you need more help with the coding post back
    Chris

  3. #3

    Thread Starter
    Addicted Member bulletrick's Avatar
    Join Date
    Jul 2005
    Location
    Philippines
    Posts
    248

    Question Re: checking wsock connection when improperly shutdown

    Quote Originally Posted by the182guy
    the best way to do this is to send out a ping to all the clients, this will determine accuratley if users online list.

    so just have your server send out a packet, it could even just send "PING" and the client must send it back when it receives it, its simple code for your data arrival sub

    if you need more help with the coding post back
    Hello, I am having problems.

    I am using this code

    VB Code:
    1. Private Sub tmrConnChecker_Timer()
    2.     Dim i%
    3.    
    4.     For i = 1 To Me.sckMain.UBound Step 1
    5.         replyReceived = False
    6.         If Me.sckMain(i).State = sckConnected Then
    7.             Me.sckMain(i).SendData "PING"
    8.             DoEvents
    9.             DoEvents
    10.    
    11.             If replyReceived = False Then
    12.                  Me.sckMain(i).Close
    13.                  ChangeStatus pmOffline, i
    14.             End If
    15.         End If
    16.     Next i
    17. End Sub
    18.  
    19. Private Sub sckMain_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    20.     Dim data$   ' variable where received data will be saved
    21.    
    22.     Me.sckMain(Index).GetData data  ' put received data to variable "data"
    23.    
    24.     If data = "OVERRIDE" Then
    25.         ChangeStatus pmOverride, Index
    26.     ElseIf data = "PING_REPLY" Then
    27.         replyReceived = True
    28.     End If
    29. End Sub 'sckMain_DataArrival()

    The timer will send a "PING" to all and the client receives it, it will send a "PING_REPLY".

    The problem is before the client has the chance to send "PING_REPLY", the server closes them.

    Thanks for the help.

  4. #4
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: checking wsock connection when improperly shutdown

    you could do it like this..

    have a timer with an interval or 2000 or 3000 maybe, the timer will wait for the ping replies, and when the code in the timer runs, it will check a boolean array which will have the replies from the clients.

    so have a boolean array in a module, then have a button on the form to check the status, the button code will have a for loop to go through the winsocks and send a "PING" to all it will the activate the timer, which will wait for the replies.

    in the data arrival sub parse the data and check if its "PING_REPLY" if it is, change the the data in the array to TRUE because that client has responded, then when the timer activates, loop through the array and count how many TRUE there is, that will be the number of connections
    Chris

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