import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public class SendDemo {
public static void main(String[] args) throws IOException {
DatagramSocket ds = new DatagramSocket();
//DatagramPacket(byte[] buf, int length, InetAddress address, int port)
byte[] bys = "hello,udp,我来了".getBytes();
InetAddress address = InetAddress.getByName("192.168.1.121");
DatagramPacket dp = new DatagremPacket(bys,bys.length,address,10000);
ds.send(dp);
ds.close();
}
} |
|