problems using magic '<broadcast>' socket address on differentplatforms

andrew cooke andrew at acooke.org
Thu May 1 18:13:53 EDT 2003


is <broadcast> a synonym for an address like 255.255.255.255 or similar? 
if so, couldn't you use the numerical address directly?

only a vague suggestion, i know nothing about broadcasting - i guess
that's why no-one else is replying either...

andrew

Irmen de Jong said:

> Myself wrote:
>> Hello
>> I'm trying to use UDP broadcasting but there are some weird things going
>> on regarding Python's magic "<broadcast>" address (which is
>> the INADDR_BROADCAST address).
> [...]
>
> Please, I'm still confused.... nobody replied :-(
>
>
>> This works fine. The problems are in the server code:
>>
>> ----
>> from socket import *
>> import select
>> import sys
>>
>> sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)
>> sock.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
>> sock.bind( ("<broadcast>", 2000) )
>>
>> while 1:
>>     (rs,ws,es)=select.select([sock],[],[],1)
>>     if sock in rs:
>>         (data, addr) = sock.recvfrom(9999)
>>         print "Got data: {%s}" % data
>>         print "from:",addr
>>     else:
>>         print ".",
>>         sys.stdout.flush()
>> ----
>
> Can somebody run this on Mac OS X, *BSD, Solaris, whatever and
> report the results? Is windows the only platform that
> got things backwards here?
>
> (or am I just doing things wrong myself...?)
>
> --Irmen de Jong.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
>


-- 
http://www.acooke.org/andrew





More information about the Python-list mailing list