udp发送端
接收端
package com.demo;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
public class Udp {
public static void main(String[] args) throws IOException {
DatagramSocket ds=new DatagramSocket(1000);
byte[] bys=new byte[1024];
DatagramPacket dp=new DatagramPacket(bys,bys.length);
ds.receive(dp);
byte[] bys2=dp.getData();
String text=new String(bys2,0,dp.getLength());
System.out.println("receive:"+text);
byte[] bys3="hi,jmeter!".getBytes();
DatagramPacket dp2=new DatagramPacket(bys3,bys3.length,dp.getSocketAddress());
ds.send(dp2);
ds.close();
}
}