public class UdpRecv
{
/** Socket ( )
* < >
* @param args
* @throws Exception
* @see [ 、 # 、 # ]
*/
public static void main(String[] args)
throws Exception
{
//
DatagramSocket ds = new DatagramSocket(8866);
byte[] b = new byte[1024];
DatagramPacket dp = new DatagramPacket(b, 1024);
ds.receive(dp);
String strRecv =
new String(dp.getData(), 0, dp.getLength()) + " from " + dp.getAddress().getHostAddress() + ":" + " :"
+ dp.getPort();
System.out.println(strRecv);
ds.close();
}
}
public class UdpSend
{
/** Socket
* < >
* @param args
* @throws Exception
* @see [ 、 # 、 # ]
*/
public static void main(String[] args)
throws Exception
{
DatagramSocket ds = new DatagramSocket();
String str = " ";
//IP IP,
DatagramPacket dp =
new DatagramPacket(str.getBytes(), str.getBytes().length, InetAddress.getByName("10.168.8.255"), 8866);
ds.send(dp);
ds.close();
}
}