Sockets

Matthew Dixon Cowles matt at mondoinfo.com
Fri Sep 14 12:43:43 EDT 2001


On Fri, 14 Sep 2001 11:19:36 -0300, Rafael Mentz Aquino
<rafael at zumnet.com.br> wrote:

>Hi, there

Hi!

>I'm trying to create a socket script to work as server, using the
>example from the lib reference manual, with a little change that puts
>the script in looping, so I can make more than one requisition
>without stopping and starting the script all the time.

>When I execute the script, it works fine, listening in the given port
>and answering the requisitions...

>But If I try to put the script in background (in FreeBSD) I got an
>error saying (address already in use). I guess its because of the
>while 1 looping...

It turns out that the reason for an address already in use error is
that the OS generally doesn't allow a server to bind to a port number
that was recently in use. I think that the logic is that some packets
intended for the old server might still be on their way from distant
corners of the net. I forget what the exact delay is and I think it
may be longer under FreeBSD than under some other OSes. In any case,
doing:

s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

will let you reuse the port immediately and make debugging easier.

Regards,
Matt



More information about the Python-list mailing list