开发者

problem with UDP broadcast?

If I broadcast using a UDP socket using sendto() and call recvfrom() immediately. I am receiving the broadcast message that I have sent from the same PC a little while ago? Can this loop back kind of thing be avoided some how?? any explanation why am I experiencing such loop back kind of thin开发者_开发百科g? I mean how long does broadcast message stays in the local n/w??


This is normal behavior. You need to read up on how UDP broadcasting actually works. Your local PC is on the same network that you are broadcasting to, so it receives the broadcast it is sending. You cannot avoid the broadcast being sent back to the local PC, but what you can do is look at the sending IP/Port that recvfrom() reports and ignore the message if it came from the same process that owns the socket that broadcasted it.

Otherwise, switch to Multicasting instead of UDP broadcasting (especially since UDP broacasting is not supported in IPv6 anyway). With Multicasting, receivers have to subscribe to the Multicast in order to receive messages, so simply do not have your sending PC subscribe to its own Multicast.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜