Skip to content
Advertisement

Why doesn’t windows desktop broadcast UDP?

Alright, so my application is a peer to peer chat application, designed for LAN communication. Discovery is done by UDP broadcasting the ip & port at the UDP broadcast address (255.255.255.255). I’m running it on three platforms at once when testing: ubuntu (VM via VirtualBox, and it’s connected to the network via VirtualBox Host-Only Ethernet Adapter), windows 10 (my development platform, and is “directly” connected to the “main” network, my router, via my wifi network adapter), and on android, where it is connected “directly” as well.

Desktop & Ubuntu share exactly the same jar executable, and android shares the same networking model, which is responsible for finding peers on the network and establishing connections, as well as broadcasting the client upon starting.

I’ll say again that the three platforms I’m running it from share exactly the same networker.

However, when I’m running my application from android and/or VM first, and then afterwards on windows 10, I discovered that the windows client will NOT broadcast itself on the broadcast address, as confirmed by my later testing with wireshark. Android and the VM WILL show up as broadcasting on the broadcasting address, while windows 10 won’t.

The code for creating the broadcast socket that sends and receives UDP broadcasts is as follows, and it’s handled by one specific thread, with no other thread having access:

public FindPeersBroadcasterRunnable() {
        try {
            broadcastSocket = new DatagramSocket(Constants.UDP_DECLARE_PEERS_PORT);
            broadcastSocket.setBroadcast(true);
            receivePacket = new DatagramPacket(new byte[Constants.MAX_PEER_NOTIFY_LENGTH], Constants.MAX_PEER_NOTIFY_LENGTH);
        } catch (SocketException ex) {
            LOGGER.log(Level.SEVERE, ex.getMessage(), ex);
        }
    }

It’s while-worthy to note that Constants.UDP_DECLARE_PEERS_PORT is 13100.

Also, these are the results from WireShark (with my IP hidden to protect my privacy):

Wireshark network sniffing results

Both android & the VM are broadcasting correctly, and I’ve checked manually that I’m using the correct adapter (I’m using my wifi adapter on windows).

Any clues and help why am I not broadcasting from windows while from the other two platforms it’s fine would be great. Thanks in advance!

Advertisement

Answer

Most likely solved: I had to bind the adapter address I’m using in order for the UDP Socket to broadcast correctly, as such:

broadcastSocket = new DatagramSocket(Constants.UDP_DECLARE_PEERS_PORT, InetAddress.getByName(IP_HERE));
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement