|
-
Jan 25th, 2006, 10:24 AM
#3
Thread Starter
New Member
Re: Socket Issue
 Originally Posted by Mike Hildner
When you say "shuts down the connection and sockets", what's the code you're using?
Also, what's your Socket.Connect code? Make sure to create a new Socket before calling .Connect and not re-use the old Socket instance.
Mike
The code to close the extended TCPClient is below.
VB Code:
Public Overloads Sub close()
Try
If (Me.Client.Connected) Then
Me.Client.Shutdown(SocketShutdown.Both)
Me.Client.Close()
End If
Me.Client = Nothing
Me.Active = False
' double check
If (m_theSocket.Connected) Then
m_theSocket.Shutdown(SocketShutdown.Both)
m_theSocket.Close()
End If
m_theSocket = Nothing
Catch e As Exception
el.WriteEntry("Client: Error closing connection - " & e.Message & vbCrLf & e.StackTrace)
End Try
End Sub
As for the connecting, after using an instance of my extended TCPClient once, I call the code above (its close() method), and then set the instance to Nothing. When I need it again for the second time, I create a new instance. The socket associated with the extended TCPClient is a member variable and is "new"'d with each call to connect() (and as you can see above, when close() is called, the socket is shutdown, closed, and set to Nothing).
I believe this is an acceptable way of doing things. It's the whole "two minutes" thing. I've read that Microsoft has some faulty port handling/releasing where it takes up to two minutes to clean up and release the port if its moved a fair bit of data, but that might just be conjecture. Any help that can be rendered would be most appreciated.
Cheers,
Duncan
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|