Hoang Manh Hung wrote:
> I start a network program that listen on a specific port (98).
> After a while the program fails and I want to restart it.
> But it said that it can't bind on that port (98), address already in
> use.
This is normally because there is a connection in the TIME_WAIT state
(see "netstat -tn").
You can get around this problem by calling
const int one = 1;
setsockopt(sock_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
before calling bind(), although it's probably better to just wait for
the old connections to complete the TIME_WAIT interval; it's there for
a reason.
--
Glynn Clements <[EMAIL PROTECTED]>
-====---====---====---====---====---====---====---====---====---====---====-
to unsubscribe email "unsubscribe linux-admin" to [EMAIL PROTECTED]
See the linux-admin FAQ: http://www.kalug.lug.net/linux-admin-FAQ/