Broadcast socket bind on Windows; '<broadcast>' or ''

Jp Calderone exarkun at intarweb.us
Sat Feb 15 23:47:40 EST 2003


On Sun, Feb 16, 2003 at 01:41:14AM +0100, Irmen de Jong wrote:
> Hi
> 
> When trying to bind a UDP socket on Windows, I get this:
> 
> >>> s=socket(AF_INET, SOCK_DGRAM)
> >>> s.bind(('<broadcast>', 9092))
> Traceback (most recent call last):
>   File "<interactive input>", line 1, in ?
>   File "<string>", line 1, in bind
> error: (10049, "Can't assign requested address")
> 
> When using '' as hostname in the bind call, it works nicely.
> 
> What's going on?
> 
> The bind with '<broadcast>' works under Linux,
> and seems to be necessary instead of '', because
> else broadcast packets might not be received from
> different network adapters.
> 

  Binding to <broadcast> is the same as binding to '255.255.255.255' on
Linux, while binding to '' is the same as binding to '0.0.0.0' (in some
systems, there is no difference between these two addresses).  The string
"<broadcast>" is not part of any kind of standard, though.  Your best bet is
to bind to '255.255.255.255', then use setsockopt() to enable SO_BROADCAST.

  Jp

-- 
 up 7 days, 8:28, 2 users, load average: 0.07, 0.04, 0.00
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20030215/3569580a/attachment.sig>


More information about the Python-list mailing list