Haim
Haim

Reputation: 21

Tcp socket suddenly closing connection

I have a chat site (http://www.pitput.com) that connects user via socket connections. I have in the client side a flash object that opens a connection to a port in my server. In the server i have a service that is listening to that port in an async matter.

All is working fine except when i talk to someone after an unknown period of time(about couple of minutes) the server is closing my connection and i get an error in the server : " A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond".

I dont know how exactly the tcp socket works. does it checking for "live" connection every couple of seconds? how does it decide when to close the connection? Im pretty sure that the close operation is not coming from the client side.

Thanks.

Upvotes: 2

Views: 3526

Answers (3)

Stephen Cleary
Stephen Cleary

Reputation: 457157

TCP/IP does have an option for checking for live connections; it's called "keepalive." Keepalives are hardly ever used. They're not enabled by default. They can be enabled on a system-wide basis by tweaking the Registry, but IIRC the lowest timeout is 1 hour. They can also be enabled on a single socket (with a timeout in minutes), but you would know if your application does that.

If you are using a web service and your client is connecting to an HTTP/HTTPS port, then it may be getting closed by the HTTP server (which usually close their connections after a couple minutes of idle time). It is also possible that an intermediate router may be closing it on your behalf after an amount of idle time (this is not default behavior, but corporate routers are sometimes configured with such "helpful" settings).

If you are using a Win32 service, then it does in fact sound like the client side is dropping the connection or losing their network (e.g., moving outside the range of a wireless router). In the latter case, it's possible that the client remains oblivious to the fact that the connection has been closed (this situation is called "half-open"); the server sees the close but the client thinks the connection is still there.

Upvotes: 1

Dennis Hostetler
Dennis Hostetler

Reputation: 624

Sounds like the server is handling the connection but not responding. This is the point where I usually pull out WireShark to find out what's going on.

Upvotes: 1

Eugenio De Hoyos
Eugenio De Hoyos

Reputation: 1775

Is this an ASP web service hosted with some company? If so, the server generally recycles apps every 10 to 20 minutes. You cannot have a web service running indefinitely, unless it's your own server (I believe).

Upvotes: 0

Related Questions