Boa tarde, estou tentando fazer um envio de comando via broadcast em uma rede windows, mas não está funcionando. Segue as minhas classes:
import java.io.*;
import java.net.*;
public class ControleBRMAClient {
public static void main(String[] args) throws IOException {
MulticastSocket socket = new MulticastSocket(4446);
InetAddress address = InetAddress.getByName("230.0.0.1");
socket.joinGroup(address);
DatagramPacket packet;
while (true) {
byte[] buf = new byte[256];
packet = new DatagramPacket(buf, buf.length);
socket.receive(packet);
String received = new String(packet.getData(), 0, packet.getLength());
System.out.pritln(received);
}
}
}
e
import java.net.*;
public class ControleBRMAServer {
protected DatagramSocket socket = null;
Socket s = new Socket();
public ControleBRMAServer() {
try {
socket = new DatagramSocket(4445);
} catch (SocketException ex) {
ex.printStackTrace();
}
}
public void comando(String comando) {
try {
byte[] buf = new byte[256];
String dString = comando;
buf = dString.getBytes();
InetAddress group = InetAddress.getByName("230.0.0.1");
System.out.println(group.getAllByName("230.0.0.1").length);
DatagramPacket packet = new DatagramPacket(buf, buf.length, group, 4446);
socket.send(packet);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Ai eu coloco as duas classes pra rodar e funciona perfeitamente local, mas se eu tento colocar o client em outra maquina da rede não funciona, simplesmente não funciona. Será que alguem pode me dar uma mão?
