Cakkie
May 27th, 2002, 07:25 PM
I'm trying to get to know Sockets in VB.Net
I have created a class which contains a thread of it's own. This thread will open a connection usinging a socket object. All goes fine, thread is working as it should, socket get's connected, sends and receives data as wanted.
The problem is that when the server closes the connection, the sockets Connected property still says True, indicating that the socket is connected, althoug the server cut the connection.
Is there a way to see if the socket disconnected?
Here's the code I use to connect
Private pSocket As Socket ' the socket
Private IPAddr As Net.IPAddress ' the address
Private EPoint As Net.IPEndPoint ' the endpoint
' create socket
pSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
' resolve address and connect
IPAddr = Net.Dns.Resolve(ServerName).AddressList(0)
EPoint = New Net.IPEndPoint(IPAddr, ServerPort)
pSocket.Connect(EPoint)
I'm absolutely sure that the server I'm connecting to disconnects me after no longer than 3 seconds. If I check the server I can see that the connection is gone, my socket say that it's still there.
I have created a class which contains a thread of it's own. This thread will open a connection usinging a socket object. All goes fine, thread is working as it should, socket get's connected, sends and receives data as wanted.
The problem is that when the server closes the connection, the sockets Connected property still says True, indicating that the socket is connected, althoug the server cut the connection.
Is there a way to see if the socket disconnected?
Here's the code I use to connect
Private pSocket As Socket ' the socket
Private IPAddr As Net.IPAddress ' the address
Private EPoint As Net.IPEndPoint ' the endpoint
' create socket
pSocket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
' resolve address and connect
IPAddr = Net.Dns.Resolve(ServerName).AddressList(0)
EPoint = New Net.IPEndPoint(IPAddr, ServerPort)
pSocket.Connect(EPoint)
I'm absolutely sure that the server I'm connecting to disconnects me after no longer than 3 seconds. If I check the server I can see that the connection is gone, my socket say that it's still there.