如何判断两台手机是处于同一局域网

时间:2022-08-03 19:02:29

发个广播包:

发组播包:

 1 //组播例子
 2 socket = new MulticastSocket(port);
 3 socket.setLoopBackMode(true);
 4 InetAddress address = InetAddress.getByName(intadd);
 5 socket.joinGroup(address);
 6 DatagramPacket packet = new DatagramPacket(data, data.length, address, port);
 7 socket.send(packet);
 8 //广播就需要
 9 socket.joinGroup(address);
10 socket.setLoopBackMode(true);
11 //给个广播地址就行