FileDocCategorySizeDatePackage
Server.javaAPI DocExample3474Thu Aug 08 12:37:34 BST 1996None

Server

public class Server extends Thread

Fields Summary
public static final int
DEFAULT_PORT
protected int
port
protected ServerSocket
listen_socket
Constructors Summary
public Server(int port)

        if (port == 0) port = DEFAULT_PORT;
        this.port = port;
        try { listen_socket = new ServerSocket(port); }
        catch (IOException e) { fail(e, "Exception creating server socket"); }
        System.out.println("Server: listening on port " + port);
        this.start();
    
Methods Summary
public static voidfail(java.lang.Exception e, java.lang.String msg)

    
    // Exit with an error message, when an exception occurs.
           
        System.err.println(msg + ": " +  e);
        System.exit(1);
    
public static voidmain(java.lang.String[] args)

        int port = 0;
        if (args.length == 1) {
            try { port = Integer.parseInt(args[0]);  }
            catch (NumberFormatException e) { port = 0; }
        }
        new Server(port);
    
public voidrun()

        try {
            while(true) {
                Socket client_socket = listen_socket.accept();
                Connection c = new Connection(client_socket);
            }
        }
        catch (IOException e) { 
            fail(e, "Exception while listening for connections");
        }