problems using magic "<broadcast>" socket address on different platforms

Irmen de Jong irmen at -NOSPAM-REMOVETHIS-xs4all.nl
Thu May 1 14:13:14 EDT 2003


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.





More information about the Python-list mailing list