组播ping回显我的客户端

因此,我正在发送一个多播数据包以发现任何可用的服务,而我得到的第一个答复是我首先发送的消息。
// create socket
InetAddress addr = InetAddress.getByName(host);
MulticastSocket socket = new MulticastSocket(port);
socket.joinGroup(addr);

// send ping
byte[] byteArray = PING.getBytes();
DatagramPacket packet =
            new DatagramPacket(byteArray, byteArray.length, addr, port);
socket.send(packet, (byte) 255);

// listen for pong
byteArray = PONG.getBytes();
packet = new DatagramPacket(byteArray, byteArray.length);
socket.setSoTimeout(2000);
socket.receive(packet); // TODO: first message is echo from me!!!
socket.receive(packet);
String response = new String(packet.getData());
Toast toast = Toast.makeText(context, \"Received \'\" + response +
            \"\' from \" + packet.getAddress(), Toast.LENGTH_LONG);
toast.show();
如何阻止这种情况发生?     
已邀请:
        您要设置多播套接字环回模式:
socket.setLoopbackMode(true); // Amusingly, this parameter is a disable
可以在Android网站上找到更多信息。     

要回复问题请先登录注册