FileDocCategorySizeDatePackage
ClientTester.javaAPI DocExample2416Sat Sep 09 20:50:14 BST 2000None

ClientTester

public class ClientTester extends Object

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


    int port;
    
    try {
      port = Integer.parseInt(args[0]);
    }  
    catch (Exception e) {
      port = 0;
    }
    
    try {
      ServerSocket server = new ServerSocket(port, 1);
      System.out.println("Listening for connections on port " 
       + server.getLocalPort());

      while (true) {
        Socket connection = server.accept();
        try {
          System.out.println("Connection established with " 
           + connection);
          Thread input = new InputThread(connection.getInputStream());
          input.start();
          Thread output 
           = new OutputThread(connection.getOutputStream());
          output.start();
          // wait for output and input to finish 
          try {
            input.join();
            output.join();
          }
          catch (InterruptedException e) {
          }
        }
        catch (IOException e) {
          System.err.println(e); 
        }
        finally {
          try {
            if (connection != null) connection.close();
          }
          catch (IOException e) {}
        }
      }
    }
    catch (IOException e) {
      e.printStackTrace();
    }