We help IT Professionals succeed at work.
Get Started

VB.NET 2008 TcpClient socket keep-alive

Last Modified: 2013-11-26

I am building a Client/Server application in VB.NET 2008. I am looking for the best way to detect when a connection is dropped (not when the server program explicitly disconnects the client, but when the line is ‘cut’).

I do not want to make a custom protocol for sending and receiving packets every few seconds to detect if the connection is still available.

Also, I am aware about the NetworkChange.NetworkAddressChanged event, from the following article on MSDN:

The NetworkChange.NetworkAddressChanged event detects only when the client unplugs his own network cable. It is not useful if the line is dropped somewhere else between the client and the server.

I know the sockets have a KeepAlive option:
myTcpClient.Client.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.KeepAlive, 1)

but is very little documentation.

I need an implementation of this in VB.NET 2008, or an solution of any kind for raising an event when the connection is dropped somewhere else between the client and the server.

Thank you.
Watch Question
Network Operations Manager
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE