Sending UDP broadcast, receiving multiple messages

The reason is when you broadcast you send your message to all the end points in the network. Since you are in the same network, you will receive the same message because it is broadcasted. You can write a custom filter for that.


Strictly speaking, packet duplication in IP network is allowed behavior of the network and you have to be able to deal with it in your software even if you will somehow get rid of it this time. If you are just wondering about why this happens in your particular case... at a first glance I see nothing wrong with your code. Do you have several IP addresses on Ethernet port of your computer or some such? I think wireshark might help get more details about what's going on.


UDP packets aren't reliable, it's totally possible that you'll get the same packet twice or even none at all, when using udp you need to include some kind of unique ID in your data so you can discard errors or request a resend.