Private Sub AcceptThread()
Dim pSocket As Socket = Nothing
Dim pClientSocket As SocketClient = Nothing
Try
'// Create a new TCPListner and start it up
GetTcpListener = New TcpListener(Dns.Resolve(GetIpAddress).AddressList(0), GetPort)
GetTcpListener.Start()
Do ' Replaces for(;;) ....
Try
'// If a client connects, accept the connection.
pSocket = GetTcpListener.AcceptSocket()
Catch e As System.Net.Sockets.SocketException
'// Did we stop the TCPListener
If Not (e.ErrorCode = 10004) Then
'// Call the error handler
GetErrorHandler(Nothing, CType(e, SocketException))
GetErrorHandler(Nothing, New Exception("Waiting for new connection 1"))
'
'// Close the socket down if it exists
If Not (pSocket Is Nothing) And pSocket.Connected Then
pSocket.Close()
End If
Else
GetErrorHandler(Nothing, New Exception("Shutting Down Accept Thread"))
'Exit For
Exit Do
End If
Catch e As Exception
'{
'// Call the error handler
GetErrorHandler(Nothing, CType(e, SocketException))
GetErrorHandler(Nothing, New Exception("Waiting for new connection 2"))
'// Close the socket down if it exists
If Not pSocket Is Nothing Then
If (pSocket.Connected) Then
pSocket.Close()
End If
End If
End Try '
Try
If (pSocket.Connected) Then
'{
Debug.WriteLine(pSocket.Connected)
'TODO: Check Code
'//Create Delegates
pClientSocket = AddSocket(New SocketClient(Me, _
pSocket, _
pSocket.RemoteEndPoint.ToString().Substring(0, 15), _
GetPort, _
GetSizeOfRawBuffer, _
GetUserArg, _
[B]New SocketClient.MESSAGE_HANDLER(GetMessageHandler), _
New SocketClient.CLOSE_HANDLER(GetCloseHandler), _
New SocketClient.ERROR_HANDLER(GetErrorHandler)[/B]))
'// Call the Accept Handler
GetAcceptHandler(pClientSocket)
'// Wait for a message
pClientSocket.Receive()
End If '} // if socket.Connected
'} // try
Catch e As FieldAccessException
'// Call the error handler
'GetErrorHandler(Nothing, e)
GetErrorHandler(Nothing, New Exception("Waiting for new connection 3"))
End Try
Loop 'Next
Catch e As Exception
'// Call the error handler
GetErrorHandler(Nothing, CType(e, SocketException))
GetErrorHandler(Nothing, New Exception("Shutting Down Accept Thread"))
'// Close the socket down if it exists
If Not (pSocket Is Nothing) And pSocket.Connected Then
pSocket.Close()
End If
End Try
End Sub