FileDocCategorySizeDatePackage
Client.javaAPI DocExample3401Thu Aug 08 12:40:14 BST 1996None

Client

public class Client extends Object

Fields Summary
public static final int
DEFAULT_PORT
Socket
socket
Thread
reader
Thread
writer
Constructors Summary
public Client(String host, int port)


    // Create the client by creating its reader and writer threads
    // and starting them.
         
        try { 
            socket = new Socket(host, port);
            // Create reader and writer sockets
            reader = new Reader(this);
            writer = new Writer(this);
            // Give the reader a higher priority to work around
            // a problem with shared access to the console.
            reader.setPriority(6);
            writer.setPriority(5);
            // Start the threads 
            reader.start();
            writer.start();
        }
        catch (IOException e) { System.err.println(e); }
    
Methods Summary
public static voidmain(java.lang.String[] args)

        int port = DEFAULT_PORT;
        Socket s = null;
        
        // Parse the port specification
        if ((args.length != 1) && (args.length != 2)) usage();
        if (args.length == 1) port = DEFAULT_PORT;
        else {
            try { port = Integer.parseInt(args[1]); }
            catch (NumberFormatException e) { usage(); }
        }
        
        new Client(args[0], port);
    
public static voidusage()

        System.out.println("Usage: java Client <hostname> [<port>]");
        System.exit(0);