Problem receiving UDP broadcast packets.

Grant Edwards invalid at invalid.invalid
Tue Apr 19 19:21:26 EDT 2011


On 2011-04-19, Irmen de Jong <irmen.NOSPAM at xs4all.nl> wrote:
> On 20-4-2011 0:21, Grant Edwards wrote:
>> I'm have problems figuring out how to receive UDP broadcast packets on
>> Linux.
>> 
> [...]
>
>> Here's the sending code:
>> 
>> --------------------------------send.py-------------------------------
>> #!/usr/bin/python
>> import sys,socket,time
>> 
>> host = sys.argv[1]
>> port = 5010
>> 
>> s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>> s.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
>> s.bind((host,port))
>
> I don't think you should use s.bind() at all in the sending code.
> Could that be at least part of the problem?

If I don't call bind(), then the broadcast packets go out the wrong
interface on the sending machine.

-- 
Grant Edwards               grant.b.edwards        Yow! Vote for ME -- I'm
                                  at               well-tapered, half-cocked,
                              gmail.com            ill-conceived and
                                                   TAX-DEFERRED!



More information about the Python-list mailing list