Create a UDP Discard Client in Java
Description
The following code shows how to create a UDP Discard Client.
Example
//w ww. jav a 2 s. co m
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
public class Main {
public static void main(String[] args) throws Exception {
InetAddress server = InetAddress.getByName("localhost");
BufferedReader userInput = new BufferedReader(new InputStreamReader(System.in));
DatagramSocket theSocket = new DatagramSocket();
while (true) {
String theLine = userInput.readLine();
if (theLine.equals("."))
break;
byte[] data = theLine.getBytes();
DatagramPacket theOutput = new DatagramPacket(data, data.length, server, 99999);
theSocket.send(theOutput);
}
}
}