sockets: bind to external interface

Thomas Rachel nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at
Mon Apr 25 23:18:05 CEST 2011

Am 25.04.2011 22:30, schrieb Chris Angelico:

> 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.

That is right, but I cannot see where he mentions the "direction" of the 
socket. My fist thought was that he tries to have a server socket...

(BTW: bind can be omitted on server sockets as well; listen() seems to 
includes a bind(('', 0)) if not called explicitly before. In this case, 
the port is assigned randomly. Can be useful in some cases, where the 
port number is not fixed...)

> 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.

If you use IPv6 and activate the privacy extensions (in order to 
periodically create a new IP address), a NIC will have even more 
addresses - the ones which aren't used any longer will be kept for a 
certain time on order not to kill any existing connections.


More information about the Python-list mailing list