Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Socket on TIME_WAIT ?? 1

Status
Not open for further replies.

Themuppeteer

Programmer
Apr 4, 2001
449
BE
Hello, can somebody tell me when a socket goes to TIME_WAIT ? and how to stop that ?

If myprogram runs for a while, I have about a 100 sockets open on TIME_WAIt and I have the feeling that it is because I don't close them correctely...

thnx guys!


grtz
themuppeteer

Greetz,
img


NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

"Those who say they understand chess, understand nothing"

-- Robert HUBNER
 
TIME_WAIT is a normal socket state. When one side closes a TCP connection, the other side (after going through a few shutdown steps) will sit in the TIME_WAIT state for some fixed period of time to ensure that the socket is indeed closed.
 
Thnx for your reply Clairvoyant1332.
Hmmm , they go away indeed after a minute or 2 if I stop sending. Could it harm anything (like blocking the process or something) if you have to many of those waiting sockets at the same time ?


Greetz,
img


NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

"Those who say they understand chess, understand nothing"

-- Robert HUBNER
 
Since you can't really control sockets sitting in the TIME_WAIT state, it isn't really an issue, however if are always opening up the same port you should use the SO_REUSEADDR option to setsockopt(3n) after calling socket(3n) so that you won't get a "socket already in use" error when you call bind(3n).
 
Thanks for your reply Clairvoyant1332.


some more info...
I'm running a client and server on the same machine. The client sends commands to the server (about 20 each second),
the server then executes this command and closes the connection. So a lot of opening and closing is going on. (its software of somebody else who made it like this a long time ago and its practicaly impossible to change this).
When a lot of communication is going on, I have an awful lot of TIME_WAIT's (more than hundred I think).

I have implemented the SO_REUSEADDR, but I still get all these TIME_WAIT sockets. How comes ? setsockopt returns 0.

Best regards,
themuppeteer


Greetz,
img


NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

"Those who say they understand chess, understand nothing"

-- Robert HUBNER
 
Setting SO_REUSEADDR will prevent the "socket already in use" error but it won't do anything about the sockets in the TIME_WAIT state. As I said before, it's a normal part of the protocol, so it's not something you really need to worry about.
 
Ok, thats all I needed to know.
Thanks a lot Clairvoyant1332, you have been very helpful!

Best regards,
themuppeteer

Greetz,
img


NOSPAM_themuppeteer@hotmail.com (for mails, remove the NOSPAM_)

"Those who say they understand chess, understand nothing"

-- Robert HUBNER
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top