FileDocCategorySizeDatePackage
UDPDiscardClient.javaAPI DocExample1110Thu Apr 03 15:25:44 BST 1997None

UDPDiscardClient

public class UDPDiscardClient extends Object

Fields Summary
public static final int
port
Constructors Summary
Methods Summary
public static voidmain(java.lang.String[] args)


       

    String hostname;

    if (args.length > 0) {
      hostname = args[0];
    }
    else {
      hostname = "localhost";
    }

    try {

      String theLine;
      DatagramPacket theOutput;

      InetAddress server = InetAddress.getByName(hostname);
      DataInputStream userInput = new DataInputStream(System.in);
      DatagramSocket theSocket = new DatagramSocket();
      while (true) {
        theLine = userInput.readLine();
        if (theLine.equals(".")) break;
        byte[] data = new byte[theLine.length()];
        theLine.getBytes(0, theLine.length(), data, 0);
        theOutput = new DatagramPacket(data, data.length, server, port);
        theSocket.send(theOutput);
      }  // end while
    }  // end try
    catch (UnknownHostException e) {
      System.err.println(e);
    }  
    catch (SocketException se) {
      System.err.println(se);
    }
    catch (IOException e) {
      System.err.println(e);
    }