xmlrpclib, connection refused? revisited

Peter Hansen peter at engcorp.com
Sun Apr 20 06:05:21 EDT 2003


Mark Gibson wrote:
> 
> Peter Hansen <peter at engcorp.com> wrote:
> : John Abel wrote:
> :>
> :> I'm guessing your using SimpleXMLRPCServer?  What interface is the
> :> server bound too?  It needs to be bound to the IP, rather than
> :> localhost.  When specifiying the host/port, try using:
> :>
> :> (socket.gethostbyname( socket.gethostname() ), 8888 )
> 
> : Better yet, use ('', 8888) as your address to listen on *all*
> : interfaces, including the loopback interface (localhost).
> 
> : -Peter
> 
> I had the same problem, and using '' fixed it.  Can someone explain it what's
> happening?

A listening port can be bound to one or more interfaces on a
computer.  Some computers have only one physical network interface,
but generally there is also a "loopback" interface, which is 
always numbered 127.0.0.1.  Connections made from the computer
to 127.0.0.1 or localhost will never go out over the network,
but will be "looped-back" inside the lower levels of the network
software *inside* the computer.

If you bind only to socket.gethostname(), your socket is *not*
listening on the loopback interface.  This means connections 
made to "localhost" will not be answered!

If you bind only to localhost, connections made from outside
the computer, across the network, will not be answered.

Listening to '' causes the network software to bind the socket
to *all* interfaces, thereby allowing you to establish both local
and remote connections.

Googling for "loopback interface" and "localhost" and "TCP/IP"
or some similar set of words would doubtless give more information,
as would another read of the documentation for the socket module.

-Peter




More information about the Python-list mailing list