1
내 네트워크에 여러 개의 서버가있어 모두 브로드 캐스트 메시지를 보냅니다. 다음 클라이언트를 사용하여 모든 서버에서 모든 브로드 캐스트 메시지를 캡처하려고합니다. 보내는 부분은 잘 작동하지만 (이 게시물에는 포함되지 않음) 수신하는 부분이 작동하지 않습니다 ... 계속 "SocketException : 멀티 캐스트 주소가 아닙니다."라는 오류 메시지가 계속 표시됩니다.Java - SocketException : 멀티 캐스트 주소가 아닙니다.
public static String[] capture(int port) { // port is always 63332
ArrayList<String> clients = new ArrayList<>();
InetAddress address = Utilities.getBroadcastAddress(); // I get "/192.168.2.255" here
MulticastSocket socket = null;
try {
socket = new MulticastSocket(port);
socket.setSoTimeout(2000);
socket.joinGroup(address); // this part throws the exception
DatagramPacket packet;
byte[] packetContent;
while (true) {
packetContent = new byte[1024];
packet = new DatagramPacket(packetContent, packetContent.length);
try {
socket.receive(packet);
String client = packet.getAddress() + ":" + packet.getPort();
clients.add(client);
} catch (IOException e) {
e.printStackTrace();
}
}
} catch (SocketException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if(socket != null) {
try {
socket.leaveGroup(address);
} catch(IOException e) {
e.printStackTrace();
}
socket.close();
}
return clients.toArray(new String[clients.size()]);
}
내가 무슨 생각을했는지 모르겠다. 고마워. – Eric