我需要通过广播将数据从手机发送到另一个我用它来发送数据
DatagramSocket udp = new DatagramSocket();
udp.setBroadcast(true);
String data = miniMe.name + "="
+ InetAddress.getLocalHost().getHostAddress();
DatagramPacket packet = new DatagramPacket(data.getBytes(),
data.getBytes().length,InetAddress
.getByName("255.255.255.255"), 7667);
while (!endBroadCasting) {
udp.send(packet);
Log.e("host lobby", "boradcast");
Thread.sleep(1000);
}
并将其用于监听数据:
castListener = new DatagramSocket(7667);
DatagramPacket listenerPacket = new DatagramPacket(buf,
300);
while (isListening) {
Log.e("gamelist", "listening called");
castListener.receive(listenerPacket);
String temp = new String(listenerPacket.getData())
.trim();
StringTokenizer token = new StringTokenizer(temp,
"=");}
但我没有从监听设备得到任何东西