Exemplo n.º 1
0
  public static void main(String args[]) {
    int port;
    String host;

    if (args.length == 1) {
      try {
        port = Integer.parseInt(args[0]);

        doEcho(port);

      } catch (IOException io_ex) {
        io_ex.printStackTrace();
        System.exit(1);

      } catch (NumberFormatException num_ex) {
        num_ex.printStackTrace();
        System.exit(1);
      }
    } else if (args.length == 2) {
      try {
        host = args[0];
        port = Integer.parseInt(args[1]);

        UDPEcho ut = new UDPEcho(host, port);
        Thread thread = new Thread(ut);
        thread.start();

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String s;
        System.out.print("Enter datagram:");
        s = in.readLine();
        while (s != null) {
          ut.send(s);
          try {
            Thread.currentThread().sleep(100);
          } catch (InterruptedException i_ex) {
          }
          System.out.print("Enter datagram:");
          s = in.readLine();
        }
        System.exit(1);

      } catch (IOException io_ex) {
        io_ex.printStackTrace();
        System.exit(1);
      } catch (NumberFormatException num_ex) {
        num_ex.printStackTrace();
        System.exit(1);
      }

    } else {
      usage();
    }
  }