How to set the socket type and the protocol of a socket using create_connection?

Hans Mulder hansmu at xs4all.nl
Wed Aug 22 05:03:11 EDT 2012


On 22/08/12 09:29:37, Guillaume Comte wrote:
> Le mercredi 22 août 2012 04:10:43 UTC+2, Dennis Lee Bieber a écrit :
>> On Tue, 21 Aug 2012 10:00:28 -0700 (PDT), Guillaume Comte
>> <guillaume.comte10 at gmail.com> declaimed the following in
>> gmane.comp.python.general:

>> 	A later follow-up

>>> Unfortunately, my_socket.bind((src_addr, 1)) doesn't work. I get the
>>> error message: "socket.error: [Errno 49] Can't assign requested address"...

>> 	Since .bind() is used to set up a /listener/, the network stack

Not necessarily.  That is, a listener is normally  bound to a
specific port, since otherwise the client doesn't know what port
to connect to (unless you provide that factoid on another port).

But nothing prevents a client from binding its socket to a
specific port number.  These days, that doesn't buy you much,
but in the old days, some services would only talk to clients
using privileged port numbers (<1024).

>> (LINK layer) probably has to be tied to the IP address; that is, a valid
>> "source" address needs to be supplied to .bind.

> Do you mean that an alias is not a valid source address? Because ping.c can do it...

> I've also tried changing the port to 3333 or 8080 but the same error happens.

On my laptop, 0 appears to be the only port number that bind accepts
for a raw socket.  Other numbers I tried all raise "socket.error:
[Errno 49] Can't assign requested address".

But this might depend on your OS.  What OS are you using?

Hope this helps,

-- HansM




More information about the Python-list mailing list