sometimes i have to send a message to a specific ip and sometimes have to broadcast the message to all ip's in my network. at the other side i have to distinguish between a broadcasted and a normal one, but recvfrom() just returns the address the message came from, and there is no difference between them, can any one help me distinguish them? udp is the protocol .
+3
A:
I don't think it's possible with Python's socket module. UDP is a very minimalistic protocol, and the only way to distinguish between a broadcast and a non-broadcast UDP packet is by looking at the destination address. However, you cannot inspect that part of the packet with the BSD socket API (if I remember it correctly), and the socket module exposes the BSD socket API only. Your best bet would probably be to use the first byte of the message to denote whether it is a broadcast or a unicast message.
Tamás
2010-05-17 11:20:52