sockets: bind to external interface

Chris Angelico rosuav at gmail.com
Mon Apr 25 16:30:59 EDT 2011


On Tue, Apr 26, 2011 at 6:14 AM, Hans Georg Schaathun <hg at schaathun.net> wrote:
> :  The way you talk of "the" external interface, I'm assuming this
> :  computer has only one. Is there a reason for not simply binding to
> :  INADDR_ANY aka 0.0.0.0?
>
> Ah.  That's what I really wanted.  Thanks a lot.  I wonder why that
> was not mentioned in the tutorial I used ...

If you don't care what port you use, you don't need to bind at all.
That may be why it's not mentioned - the classic TCP socket server
involves bind/listen/accept, and the classic TCP client has just
connect; bind/connect is a lot less common.

Incidentally, interfaces don't have to correspond 1:1 to network
cards. At work, we have a system of four IP addresses for each server,
even though it has only one NIC - it's used for traffic management and
routing. Binding to a specific address is sometimes important there.

Chris Angelico



More information about the Python-list mailing list