Winsock Control and Responding to Error Situations
From: Bradley M. Small (BSmall_at_XNOSPAMXmjsi.com)
Date: 03/05/04
- Previous message: Peter: "http command in VB6.0 coding"
- Messages sorted by: [ date ] [ thread ]
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
- Previous message: Peter: "http command in VB6.0 coding"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|