How to identify a broadcasted message?
Sometimes I have to send a message to a specific IP and sometim开发者_Python百科es I have to broadcast the message to all the IP's in my network. At the other end I have to distinguish between a broadcast and a normal one, but recvfrom()
just returns the address the message came from;
there is no difference between them. Can anyone help me distinguish them?
UDP is the protocol.
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.
精彩评论