tcp client socket bind problem

Dan Stromberg dstromberglists at gmail.com
Thu Mar 13 00:51:24 CET 2008


On Sun, 09 Mar 2008 22:21:59 -0700, natambu wrote:

> I have a linux box with multiple ip addresses. I want to make my python
> client connect from one of the ip addresses. Here is my code, no matter
> what valid information I put in the bind it always comes from the
> default ip address on the server. Am I doing something wrong?
> 
> 
> -------------
> #!/usr/bin/python
> 
> import socket
> 
> host = "server"
> port = 1190
> 
> sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> 
> sock.bind(("<ipalias>",0))
> sock.connect((host, port))
> -------------

I'd've expected that to work.

What does your routing table look like?  You can view it with "netstat -
nr".  I believe when a Linux network interface is ifconfig'd, the kernel 
will add a route for that interface based on the netmask in the ifconfig, 
but you could conceivably have another route that is broader overriding 
the specific route.




More information about the Python-list mailing list