Results 1 to 10 of 10

Thread: winsock client closure

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2001
    Location
    Calif USA
    Posts
    42

    Smile winsock client closure

    Hey all you winsock fans! (my cherry post!)

    Ive been working on a chat server/client and am having
    a problem with remote termination of a client crashing the server
    Everything works fine if the remote user uses the designed
    means by which to exit the prog. but if their ISP kicks it then
    it crashes my server. As the winsock control for the the terminated
    client is still active on the server,the server will
    still try to echo back to the disconnected client. I would like to
    know the most efficient way to verify connectivity and/or take
    the appropriate action when it ceases.

    ie. Will the 'if winsock=sckclosed' actually determine if a sudden
    remote termination has taken place, like an remote system crash?

    or should i 'ping' the client with a packet of data bound to a timer,
    wait for a nonresponse and take the appropriate client closure
    action during the error event?

    im looking for the most comprehensive and most efficient answer
    involving the least amount network congestion that will
    allow for the continuous, fluid function of the server/host.


    “All that is necessary for the triumph of evil is that good men do nothing”-Edmund Burke.

  2. #2
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    You recieve a "Close" event when a remote system disconnects from your system.
    Baaaaaaaaah

  3. #3
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I usually have a refresh loop that I do now and then (actually whenever there is a change in the userlist).

    Which basically checks the sock and if its not connected it closes it.

    VB Code:
    1. If wsServer(x).state<>sckConnected then
    2.     wsServer(x).close
    3. end if

    Thats not the exact code I use, because I don't have it with me right now, but you get the picture.

  4. #4
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728

    Smile Info.

    Make use of the Winsock Error event. i.e.
    VB Code:
    1. Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    2.    
    3.     Select Case Number
    4.        
    5.         Case sckConnectionReset
    6.        
    7.             Debug.Print "Error: Connection reset by remote client."
    8.        
    9.         'Case ...
    10.        
    11.     End Select
    12.    
    13. End Sub

    This will inform you of any significant event such as a disconnection etc. The constants are listed in the VB Object browser, and in MSDN.

    Hope this helps.
    Laterz
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

  5. #5
    Stiletto
    Guest
    I'm working on a chat prog too.
    Can some1 plz tell me how can i use the winsock with multi users?

  6. #6
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Baaaaaaaaah

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2001
    Location
    Calif USA
    Posts
    42
    WOW! thanks guys!
    I just got in from class and it might take me a little bit to implement
    some fo the suggestions...ill let you know!
    -THX!
    “All that is necessary for the triumph of evil is that good men do nothing”-Edmund Burke.

  8. #8

    Thread Starter
    Member
    Join Date
    Nov 2001
    Location
    Calif USA
    Posts
    42

    Arrow

    HEY ...im back!

    *ABDUL... yes i recieve a close event if the client closes NORMALLY
    but if they're terminated buy their network connection (ie crummy ISP)
    then winsock dosent evoke the close event..the only way to know
    is when you try to send something else to that client and get the
    error.....so far!

    *Edneeis, im working on a solution in line with what you have
    suggested. but im going to have to clean up my code abit to
    make it work in its own seperate event ( because i have unload the wsServer()
    control in another err. event

    *digital, I think your way is the proper way to go but i tried to evoke a
    failure on my subnet and failed (ie It worked fine) so im holding out
    for my friend with the crummy ISP to trip it and see whats up.
    but such a remedy is obviously best left to an errorhandler

    SYNOPSIS
    I am coding in both into the prog. and will await subsequent crashes.
    Theyre not frequent but they do happen and it annoys me to see my
    server crashed when i come home!)

    I'm working on a chat prog too.
    Stiletto.
    Each client has its own winsock control
    the server loads a SEPERATE control as an array at runtime upon a connection request
    ie. wsServer(x) to make the control an array, when you load the control on the server form put a 'zero' in the index box!

    if you need more help there are many posts here or
    i can send you a cool .zip example i dnloaded from www.vbcode.com with FULL notation included!
    (i dont have the link but i have the .zip vb prog)
    email me...... [email protected]
    “All that is necessary for the triumph of evil is that good men do nothing”-Edmund Burke.

  9. #9

    Thread Starter
    Member
    Join Date
    Nov 2001
    Location
    Calif USA
    Posts
    42
    thx digital! worked great!

    I unload the client when the error event occurs and Voila!
    and I write the err. description ot a .log file for future reference!
    “All that is necessary for the triumph of evil is that good men do nothing”-Edmund Burke.

  10. #10
    Fanatic Member
    Join Date
    Sep 2000
    Location
    UK.
    Posts
    728
    Originally posted by jhov
    thx digital! worked great!

    I unload the client when the error event occurs and Voila!
    and I write the err. description ot a .log file for future reference!
    Digital-X-Treme
    Contact me on MSN Messenger: [email protected]

    [VBCODE]Debug.Print Round(((1097) - ((55 ^ 5 + 311 ^ 3 - 11 ^ 3) _
    / (68 ^ 5))) ^ (1 / 7), 13)[/VBCODE]

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