Results 1 to 2 of 2

Thread: Prevent winsock close on closing main dialog

  1. #1

    Thread Starter
    Fanatic Member hothead's Avatar
    Join Date
    Mar 2002
    Location
    Missouri
    Posts
    692

    Prevent winsock close on closing main dialog

    Here's my code.

    Code:
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        Set db = Nothing
        Set fso = Nothing
        Set rs = Nothing
        Set Win32Script = Nothing
        Set WkSpc = Nothing
        wskConnectionHandler.SendData CLIENT_MESSAGE_DISCONNECTED
        wskConnectionHandler.Close
        Unload Me
    End Sub
    This is supposed to send a disconnect packet when the user clicks the close button. However, I get an error "Invalid operation at current state." Debugging revealed that this is because the Winsock control begins to close the connection immediately after the user clicks the X, and this is bad because the server will never know that the client has disconnected when they click the X. How can I prevent this from happening?

  2. #2
    Lively Member Spetnik's Avatar
    Join Date
    Jan 2002
    Posts
    121

    Re: Prevent winsock close on closing main dialog

    I am not sure what else is going on in your app.

    I created a form with command1 and winsock1 and the following code, clicked command1 and then exited the program with no errors

    Code:
    Option Explicit
    
    Private Sub Command1_Click()
        Winsock1.Connect "www.google.com", "80"
    End Sub
    
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
        Winsock1.SendData "a"
    End Sub

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