[Twisted-Python] Socket bind and re-bind problems
James Y Knight
foom at fuhm.net
Tue Aug 9 14:21:57 EDT 2005
On Aug 9, 2005, at 12:44 PM, Gaballo Luca wrote:
> hi,
> i'm working with socket and i need to make two consecutive
> connection binding the client on the same address. When i try to
> execute the code i have an error like this:
> socket.error: (98, 'Address already in use')
> even if i have correctly closed the socket !?!
The kernel prevents you from reusing a local port for a few seconds
in order to properly implement some timeout in the TCP spec. You
don't really want to bypass this. There is pretty much no reason to
ever bind a client tcp socket to a specific port. So, your problem is
solved simply by removing the 'bind' call. Or, if you do want to bind
to a local IP addr, simply set the local port to 0 so the kernel will
autoselect.
James
More information about the Twisted-Python
mailing list