UDP 简单
1、
发送数据
1 public static void SendUDP(String _strIp, int _iPort, byte[] _bufSend) throws Exception 2 { 3 //DatagramSocket local = new DatagramSocket(_iPort); 4 DatagramSocket local = new DatagramSocket(); 5 InetAddress addrDest = InetAddress.getByName(_strIp); 6 //addrDest.isReachable(5000); 7 DatagramPacket sendPacket = new DatagramPacket(_bufSend, _bufSend.length, addrDest, _iPort); 8 local.send(sendPacket); 9 local.close(); 10 }
DatagramSocket 构造函数,如果传入端口号的话 是本地使用的端口号。
X