I'm trying to send a UDP broadcast on IP address "255.255.255.255" for device discovery in my network. The program executes, but I don't see anything in Wireshark. when I'm changing the IP address to a known IP in my network, I can see the packets in Wireshark. what's going on ?
This is my code:
public static void main(String args[]) throws Exception
{
String Broadcastaddress = new String("255.255.255.255");
int port = 9876;
DatagramSocket serverSocket = new DatagramSocket();
serverSocket.setBroadcast(true);
InetAddress IPAddress = InetAddress.getByName(Broadcastaddress);
System.out.println("Sending Discovery message to " + IPAddress + "Via UDP port " + port);
byte[] sendData = new byte[4];
sendData[0] = 'F';
sendData[1] = 'I';
sendData[2] = 'N';
sendData[3] = 'D';
DatagramPacket sendPacket = new DatagramPacket(sendData,sendData.length,IPAddress,port);
while (true)
{
serverSocket.send(sendPacket);
System.out.println("Packet sent");
}
}