Android项目记录点滴2

1.把本机地址广播出去
private void sendIP() {
try {
DatagramSocket dgSocket = new DatagramSocket(8989);
byte[] by = _ipString.getBytes();
try {
DatagramPacket packet = new DatagramPacket(by,by.length, InetAddress.getByName(_broadcastAddress),8989);
try {
dgSocket.send(packet);
} catch (IOException e) {
e.printStackTrace();
}
dgSocket.close();
} catch (UnknownHostException e) {
e.printStackTrace();
}
} catch (SocketException e) {
e.printStackTrace();
}
}
2.在服务器端用了三个端口,一个端口用来发送数据,一个端口用来连接用户,一个用来广播主机的IP地址

你可能感兴趣的:(android)