import java.net.*;
class UdpSend
{
public static void main(String[] args) throws Exception
{
DatagramSocket ds = new DatagramSocket(8888);
byte[] buf = "udp im coming".getBytes();
DatagramPacket dp = new DatagramPacket(buf,buf.length,InetAddress.getByName("192.168.1.102"),10001);
ds.send(dp);
ds.close();
}
}
//--------------------
class UdpRece
{
public static void main(String[] args) throws Exception
{
DatagramSocket ds = new DatagramSocket();
byte[] buf = new byte[1024];
DatagramPacket dp = new DatagramPacket(buf,buf.length);
ds.receive(dp);
String ip = dp.getAddress().getHostAddress();
String data = new String(dp.getData(),0,dp.getLength());
int port = dp.getPort();
System.out.println(ip+"::"+data+"::"+port);
ds.close();
}
}
//---------------------------------------
一切步骤和按毕老师的一样, 就是接收不到消息, 为什么???????????
毕老师的是 xp系统, 我的是 win8.1 笔记本 wifi, 和这有关系吗???
|
|