package test;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
class UdpSe
{
public static void main(String[] args) throws Exception
{
DatagramSocket ds=new DatagramSocket(888);
// BufferedReader sb=new BufferedReader(new InputStreamReader(System.in));
String tb="dfsfs";
// while((tb=sb.readLine())!=null){
// if("886".equals(tb))
// break;
//
byte[] byt=tb.getBytes();
DatagramPacket dp=new DatagramPacket(byt,byt.length,InetAddress.getByName("192.168.1.103"),10002);
ds.send(dp);
ds.close();
}
}
class UdpRa
{
public static void main(String[] args) throws Exception{
DatagramSocket ds=new DatagramSocket(10002);
byte[] byy=new byte[1024];
DatagramPacket dp=new DatagramPacket(byy,byy.length);
ds.receive(dp);
String ip=dp.getAddress().getHostAddress();
String data=new String(dp.getData(),0,dp.getLength());
int port=dp.getPort();
System.out.print(ip+data+port);
ds.close();
}
}接收端,就不到东西。 |
|