UDP Discard Client : UDP Client « Network « Java Tutorial






import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class MainClass {

  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);
    }

  }

}








19.17.UDP Client
19.17.1.UDP Echo Client
19.17.2.UDP Discard Client
19.17.3.UDP Time Client
19.17.4.Send a Datagram
19.17.5.Sending a Datagram
19.17.6.Receiving a Datagram
19.17.7.Read and write with DatagramPacket
19.17.8.User Datagram Protocol Programming