PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, September 12, 2022

[FIXED] Why doesn't windows desktop broadcast UDP?

 September 12, 2022     broadcast, cross-platform, java, networking, udp     No comments   

Issue

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!


Solution

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));


Answered By - g_elef
Answer Checked By - Timothy Miller (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing