problem with SocketServer -- address already in use
Andreas E. Wrede
awrede at home.com
Tue Jul 13 18:03:04 EDT 1999
Phil Hunt wrote:
>
> I'm trying to use SocketServer.py to write a TCP server. I ran
> my program with ``python serv.py'', which went into an infinite
> loop (which is what it should do). I exited my program with ^Z,
> and tried to start it up again. I got an error message:
>
> socket.error: (98, 'Address already in use')
>
> which I presume is because something thinks the old invokation of
> my program is still using port 7070.
>
> How do I clear the port, before I start up my server?
The sockets stays allocated and in use for some timeout period after you
close it.
I solved this one by setting the SO_REUSEADDR option thru overridding
server_bind:
def server_bind(self):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1)
SocketServer.TCPServer.server_bind(self)
--
- aew
More information about the Python-list
mailing list