TcpClient timeout?

  • Thread starter Thread starter Danny Tuppeny
  • Start date Start date
D

Danny Tuppeny

Hi all,

I'm using a TcpClient to talk to a newserver. If I don't send any data for a
while, will the connection timeout, or does something in the TcpClient keep
it alive? If not, and it times out, how do I keep it alive without actually
sending data?

Thanks,
 
Danny,

In .NET 2.0, I believe the TcpClient exposes the underlying socket
through the Client property (it used to be protected, if I remember
correctly). Once you get the socket (by deriving from TcpClient in .NET 1.1
or through the public Client member in 2.0) you can call SetSocketOption,
passing in KeepAlive, to help manage keeping the socket alive.

Mind you, depending on the server (if you don't have control over it or
not), it might actually shut down the connection for some reason or another
(depending on the behavior it wants).

Hope this helps.
 
Nicholas Paldino said:
In .NET 2.0, I believe the TcpClient exposes the underlying socket
through the Client property (it used to be protected, if I remember
correctly). Once you get the socket (by deriving from TcpClient in .NET
1.1 or through the public Client member in 2.0) you can call
SetSocketOption, passing in KeepAlive, to help manage keeping the socket
alive.

Mind you, depending on the server (if you don't have control over it or
not), it might actually shut down the connection for some reason or
another (depending on the behavior it wants).

Thanks Nicholas, that helps a lot :)
 
Back
Top