Create DatagramPacket from byte array
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
class Main {
public static void main(String args[]) throws Exception {
InetAddress ia = InetAddress.getByName(args[0]);
int port = Integer.parseInt(args[1]);
DatagramSocket ds = new DatagramSocket();
while (true) {
String s = "asdf";
byte buffer[] = s.getBytes();
DatagramPacket dp = new DatagramPacket(buffer, buffer.length, ia, port);
ds.send(dp);
}
}
}
Related examples in the same category