I\'m programming a networking program in java , and I want to send some Packets to 255.255.255.255, but it fails , even when I send them to 192.168.1.255, which according to
Rather than connect your DatagramSocket to the broadcast address, just construct the DatagramPacket to target it, i.e.
DatagramPacket dp = new DatagramPacket(byteArray, byteArray.length, InetAddress.getByName("255.255.255.255"), yourPortNumber);
And like magic, you've sent a broadcast. And then to catch it on the other side, just have that end listening on that port:
DatagramSocket dsock = new DatagramSocket(samePortUsedAbove);
DatagramPacket dp = new DatagramPacket(byteArray, byteArray.length);
dsock.receive(dp);