System.Net.Sockets class

  • Thread starter Thread starter Alain Dekker
  • Start date Start date
A

Alain Dekker

Hi,

I've created a socket like this:

ipAddress = ipAddress.Parse(strAddress)
ipRemoteEP = New IPEndPoint(ipAddress, nPort)

m_Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp)
m_Socket.BeginConnect(ipRemoteEP, AddressOf ConnectCallback, m_Socket)

and that all works fine (ie. the ConnectCallBack function is called when the
connection is made). However, I've hit a snag: How do I get signalled when
the remote server disconnects (crashes/shuts down/closes the
connection/etc)?

Thanks,
Alain
 
Hi,

I've created a socket like this:

ipAddress = ipAddress.Parse(strAddress)
ipRemoteEP = New IPEndPoint(ipAddress, nPort)

m_Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp)
m_Socket.BeginConnect(ipRemoteEP, AddressOf ConnectCallback, m_Socket)

and that all works fine (ie. the ConnectCallBack function is called when the
connection is made). However, I've hit a snag: How do I get signalled when
the remote server disconnects (crashes/shuts down/closes the
connection/etc)?

You don't... That's because that's how tcp/ip is implemented. You know when
the remote host is down when you do a receive on the socket and it returns 0.
 
Back
Top