Winsock Control and Responding to Error Situations

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Bradley M. Small (BSmall_at_XNOSPAMXmjsi.com)
Date: 03/05/04

  • Next message: Randy Birch: "Re: [Vb.net question] how to apply online update function into program (the effect just like Norton system work live update)"
    Date: Fri, 5 Mar 2004 09:52:01 -0500
    
    

    I have an application that impliments the winsock control in a control array
    to handle multiple connections. This seems to work fine for the most part.
    However, occasionally when I get an error event sckServer_Error(), my
    program will DR. Watson out with an 00005.

    I must associate other data with the socket so I have a dictionary that
    associates them via the TAG field which I set based on the requestid.

    So when I close the socket I call a function CloseSocket. This and the event
    are below. I do reveive the output marked by "'************* I get this
    output **************" but after that the program is gone.

    Any ideas and suggestiosn are welcome.

    Thanks

    -- B

    -----
    -- global public function to handle closing a socket
    Public Sub CloseSocket(sckThis As Winsock)
    Const strCurrFunct As String = "CloseSocket"

        Dim strMsg As String
        Dim strTag As String

    On Error Resume Next

        ' gets tag string to get associated dictionary value
        strTag = sckThis.Tag

        ' remove the dictionary element
        g_dictSocket.Remove strTag

        ' test state to determine if socket is already closed
        If sckThis.State <> sckClosed Then
            ' close the socket
            sckThis.Close
        End If

        ' test for error state
        If Err.Number = 0 Then
            strMsg = "(" & strTag & ") > Closed Successfully"
        Else
            strMsg = "(" & strTag & ") > ** CloseSocket ERROR *** " &
    Err.Description
        End If

    '************* I get this output **************
        ' output message that logs to a database
        Output strMsg

        ' in the control array the first socket has the tag of 'Base' because
        ' this is the design time control it can't be unloaded
        If sckThis.Tag <> "Base" Then
            Unload sckThis
        End If

        ' this number will later be used to add a new control to the array
        ' during connect requests with the code:
        ' g_intMax = g_intMax + 1 ' increment
    ubound
        ' Load sckServer(g_intMax) ' load a new
    socket
        g_intMax = frmMain.sckServer.UBound

    '*********** this never happens ***********'
        ' catch errors not specifically handled up to this point
        If Err.Number <> 0 Then
            MsgError "Unhandled exception #" & Err.Number & " Err:" &
    Err.Description, strCurrFunct
        End If
    End Sub

    Private Sub sckServer_Error(iIndex As Integer
        , 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)

    Const strCurrFunct As String = "frmMain.sckServer_Error"

        Dim sckThis As Winsock

    On Error Resume Next

        ' if I receive a blocking error on the base socket then clear it and
    listen again
        If iIndex = 0 And Number = sckWouldBlock Then ' clears blocking
    errors on listener (special case)
            sckServer(0).Listen
            Exit Sub
        End If

        ' get a socket from the index
        Set sckThis = sckServer(iIndex) ' gets an actual
    socket from the index

        ' shows the error message
        Output "Unhandled Error from index#" & iIndex & " tag<" & sckThis.Tag &
    "> err#" & Number & " desc:" & Description & " Scode:" & Scode & " Source:"
    & Source

        ' calls the close socket routine to keep things in order
        CloseSocket sckThis

        ' catch all for errors
        If Err.Number <> 0 Then
            Output "Unhandled error Err:" & Err.Description
        End If

        'cleanup
        Set sckThis = Nothing
    End Sub


  • Next message: Randy Birch: "Re: [Vb.net question] how to apply online update function into program (the effect just like Norton system work live update)"

    Relevant Pages

    • Re: Simple Insert Into...
      ... You can store unbound control data in a variable, ... in the sql. ... Dim strSQL As String ... In your form's Sub, you'll wind up with something like the following: ...
      (microsoft.public.access.modulesdaovba)
    • Custom Query from user response
      ... >>form I can Construct a SQL string. ... >>string to the report. ... >of each control to build a selection string which I then ... >cmdPreviewReport sub below. ...
      (microsoft.public.access.queries)
    • Re: Multithreading the Winsock Control
      ... > is a known memory leak when repeatedly unloading WinSock control. ... >> Dim msg As String ... >> Exit Sub ... >> Dim Source As String ...
      (microsoft.public.vb.controls)
    • Re: Writing Access functions
      ... Otherwise, create a sub. ... Control sources, Macros (thought the only one you should be using is the ... Public Function NameFromIDAs String ...
      (microsoft.public.access.modulesdaovba)
    • Custom Query from user response
      ... >form I can Construct a SQL string. ... store in another control on the form. ... Private Sub cboBuildingType_AfterUpdate ... For Each ctl In Me.Controls ...
      (microsoft.public.access.queries)