in dubbo-remoting-extensions/dubbo-remoting-p2p/src/main/java/org/apache/dubbo/remoting/p2p/exchange/support/MulticastExchangeGroup.java [44:74]
public MulticastExchangeGroup(URL url) {
super(url);
if (!NetUtils.isMulticastAddress(url.getHost())) {
throw new IllegalArgumentException("Invalid multicast address " + url.getHost() + ", scope: 224.0.0.0 - 239.255.255.255");
}
try {
multicastAddress = InetAddress.getByName(url.getHost());
multicastSocket = new MulticastSocket(url.getPort());
multicastSocket.setLoopbackMode(false);
multicastSocket.joinGroup(multicastAddress);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
byte[] buf = new byte[1024];
DatagramPacket recv = new DatagramPacket(buf, buf.length);
while (true) {
try {
multicastSocket.receive(recv);
MulticastExchangeGroup.this.receive(new String(recv.getData()).trim(), (InetSocketAddress) recv.getSocketAddress());
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
}
}
}, "MulticastGroupReceiver");
thread.setDaemon(true);
thread.start();
} catch (IOException e) {
throw new IllegalStateException(e.getMessage(), e);
}
}