,DatagramSocket data= new DatagramSocket();
String str = "123";
DatagramPacket datapacket = new DatagramPacket(str.getBytes(),str.length(),InetAddress.getByName("localhost"),7000);
dataSocket.send(datapacket);
byte[] by = new byte[4096];
DatagramPacket dataPacket2 = new DatagramPacket(by,4096);
dataSocket.receive(dataPacket2);
udp必须和服务器建立对应的端口号,具体的话,楼主可以在网上直接找相关的demo.