TCP option Keepalive.

K

Kalpesh Modha

Hello.

I sometimes get this error message "An existing connection was forcibly
closed by the remote host" for no reason what so ever in my program. I was
wondering keepalives would help in this matter. My program runs fine and
then all of a sudden the client dies and this message is what is left in the
server logs.

If I was to enable keepalive would the server and client both need it
enabling in the programs ? or just the client ? or just the server ?

If any has any ideas why this would happen let me know.

Thanks
Kalpesh Modha

Ps VS 2003, .NET 1.1 Sp1 Windows xp pro Sp2,
 
P

Paul O'Connell

How long does the client stay connected. From what I remember the KeepAlive
option was designed for long running connections such as those used by
Telnet and is only sent every couple of hours or so. Although it is possible
to bring this time down. There is some problem with changing the value
though but I can't quite remember what. I think it might that if you chnage
it the change is global i.e. affects all of the TCP connections. The advice
I have seen is to implment your own ping mechanism which kicks in once the
connection has been idle for a set period of time. If the two machines are
not directly connected i.e. there are routers/repeaters/gateways between the
two machines then this could indicate a problem with the router. Which could
be dropping what it thinks of as an idle connection in favour of something
more active.

A good refeence book on TCP/IP is

TCP/IP Illustrated Volume 1: The Protocols
W. Richard Stevens
Addison Wesley Professional Computing Series
0-201-63346-9

Paul.
 
K

Kalpesh Modha

Hello.

Thanks for the information provided.

The program(client) can stay connected
for 7 -8 hours and then all of a sudden just die. I do have an OK message
sent every 50 seconds from the client to keep the connectin up.

The werid thing is that there are services also written in C# which run on
the same machine as the service the client connects too and again these
produce the same message.

I was thinking of running a network sniffer to see why end actually forces
the closure.

regards
Kal.
 
P

Paul O'Connell

That sounds like something more fundamental is wrong. I've written programs
in C# that have stayed connected to their servers for days, well probably
weeks actually. If this problem is affecting serveral different programs
then running somehting like ethereal would be a good idea. the other think
to check is does it affect any other programs. If you have time perhaps you
should try writting the client in something like C++ and not use C#/.Net. It
doesn't have to be a full implementation just enough to do something useful
and see if that also suffers from the problem. That will at least remove
..Net from the equation. The other thing to try is a really basic client in
C# and then keep adding functionality until it stops working. That might
narrow it down to a particular piece of functionality.

Thats about all I can think of I'm afraid.

Paul.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top