Browse thread
Error binding socket
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | skaller <skaller@u...> |
| Subject: | Re: [Caml-list] Error binding socket |
On Wed, 2005-11-09 at 13:33 +0100, Maurizio Colucci wrote:
> Hi there. For my free tennis game (http://freetennis.sf.net), I get an
> error binding the socket to a port. (Unix_error 50, "bind"). The error
> description is "address already in use".
>
> This error only happens the *second* time I start the program. It is
> as if the port had not been freed and were still in use. The system is
> GNU/Linux Ubuntu Breezy.
>
> However, if I wait about 1minute, or I start the program specifying a
> different port, the problem does not happen. It is as if Linux were
> freeing the port with a delay.
This is standard Unix behaviour.
use the setsockopt() function, these options may help
(from man 7 socket), I forget the Ocaml for this, but I know
it can be done because I had exactly the same problem myself once.
SO_REUSEADDR
Indicates that the rules used in validating addresses
supplied in a bind(2) call
should allow reuse of local addresses. For PF_INET
sockets this means that a
socket may bind, except when there is an active listening
socket bound to the
address. When the listening socket is bound to
INADDR_ANY with a specific port
then it is not possible to bind to this port for any local
address.
SO_LINGER
Sets or gets the SO_LINGER option. The argument is a
linger structure.
struct linger {
int l_onoff; /* linger active */
int l_linger; /* how many seconds to linger for */
};
When enabled, a close(2) or shutdown(2) will not return
until all queued mesā
sages for the socket have been successfully sent or the
linger timeout has been
reached. Otherwise, the call returns immediately and the
closing is done in the
background. When the socket is closed as part of
exit(2), it always lingers in
the background.
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net