Binding to specific IP addresses

Graham Ashton graz at
Thu Aug 23 11:55:49 CEST 2001

[Having just written this post I've realised that to summarise, I might
just be asking "how do I avoid binding a socket to all interfaces?".

I've got a problem with an application that uses a subclass of 
SocketServer.TCPServer. It doesn't seem to behave itself when binding 
sockets to IP addresses.

Here is a snippet of code:

  print "binding to %s:%d" % (self.server_ip, self.server_port)
  self.server = MyTCPServer((self.server_ip, self.server_port), MyHandler)

The self.server_ip is set to "", rather than the empty string,
which I understand to mean that the server will only listen for inbound
requests on that IP address, not on my dial up PPP connection.

MyTCPServer (being a subclass of SocketServer.TCPServer) calls
self.server_bind() from it's __init__() method. After the code above has
been run I get a traceback:

ratchet% ./ 
binding to
Traceback (most recent call last):
  File "./", line 176, in ?
  File "./", line 100, in run
    self.server = MyTCPServer((self.server_ip, self.server_port), MyHandler)
  File "./", line 42, in __init__
  File "/usr/local/lib/python2.1/", line 322, in __init__
  File "/usr/local/lib/python2.1/", line 333, in server_bind
socket.error: (98, 'Address already in use')

The lsof program tells me that the process that is using the address is
my dial up software, pppd. I find this very surprising as the
address is the address of my ethernet card and has nothing to do with my
dial up connection.

Can anybody shed some light on this for me? Is there something that I
ought to be doing to avoid listening on other interfaces?



P.S. I've been through the self.allow_reuse_address = 1 thing already, so
that shouldn't be the problem.

More information about the Python-list mailing list