Click to See Complete Forum and Search --> : How can I make a PERFECT RE-USABLE SOCKET ?


novice00
July 22nd, 2005, 01:48 AM
I have some problems to make a network component.

It is a "TIME_WAIT" state on client socket.

When the socket is in "TIME_WAIT" state, it cannot connect into any remote server.

How can I avoid "TIME_WAIT" state?

Or, is there any function that can check a socket in "TIME_WAIT" or not ?



I disconnect all sessions using "DisconnectEx" function for re-using socket.

And, all sockets are pre-binded.

There are no problem when I disconnect client from server.

But, client disconnects itself and then socket falls in "TIME_WAIT" state.

I tryed to remove that state, but I can't. (failed..all)

I applied handshaking routine, LINGER option and changing into blocking mode..

As you know, TIME_WAIT state's duration is so~~~~ long!!

So, I want to know, how to check it or avoid it. ( TIME_WAIT state )



--
( NOVICE )
Student~
Seoul. Korea.

Mathew Joy
July 26th, 2005, 03:33 AM
For binding a socket which in "TIME_WAIT" state, you can use SO_REUSEADDR socket option.

Richard.J
July 26th, 2005, 03:12 PM
Are you talking about a 'client'? A client does not need to bind to a specific port, so setting it to 0 would let the OS choose a free port. Normally, only servers need to bind a port, in which case Mathew's post applies.

Mathew Joy
July 27th, 2005, 01:57 AM
Sorry my last post is incorrect. Sockets that are in TIME_WAIT state cannot be reused. I was thinking of using other sockets at that time. :blush: