problem solved replace the broadcast IP "255.255.255.255" by the Local area broadcast Address "192.168.1.255"
Broadcasting a UDP datagramPacket over LAN
-
04-07-2022 - |
Question
I am a beginner in Network programming. And
I am trying to build a peer to peer network application using UDP Datagramsocket in java.
and I need to broadcast messages between the peers on different hosts (PCs running windows 7 connected to my local area network).
and I use the following code to broadcast a message:mySocket = new DatagramSocket(myport);
mySocket.setBroadcast(true);
broadCastPacket = new DatagramPacket(packetbroad, packetbroad.length ,
InetAddress.getByName("255.255.255.255"), 11235);
mySocket.send(broadCastPacket);
when I test this on a single PC it works fine. But the problem occurs when I test it on different end systems ( hosts / two PCs ) : No one of these two hosts receive any broadcasted message from the other although my router enable broadcasting and all firewalls on all hosts are disabled. could you please help me ?
Solution