package com.zy;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public class Udpclinet {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
DatagramSocket ds=new DatagramSocket(8888);
String s="你好服务器";
DatagramPacket dp=new DatagramPacket(s.getBytes(), s.getBytes().length,InetAddress.getLocalHost(),9999 );
ds.send(dp);
byte b[]=new byte[1024];
DatagramPacket ndp=new DatagramPacket(b, b.length);
ds.receive(ndp);
System.out.println(new String(b).trim());
ds.close();
}
}