Pig Latin Problem Set Javadocs

cs101.net
Class Client

java.lang.Object
  extended bycs101.net.Client
All Implemented Interfaces:
java.lang.Runnable, StringHandler

public class Client
extends java.lang.Object
implements java.lang.Runnable, StringHandler

A reasonably vanilla network client. Works with Server.java. To customize, provide it with a StringHandler, either at creation time or later.

If server's hostName and port are not provided at creation time, the user is prompted for this information using ClientDialog.

Copyright 1996 Massachusetts Institute of Technology

Version:
$Id: Client.java,v 1.1.1.1 2002/06/05 21:56:32 root Exp $
Author:
Todd C. Parnell, tparnell@ai.mit.edu, Maciej Stachowiak, maciej@ai.mit.edu, Lynn Andrea Stein, las@ai.mit.edu
See Also:
Server, StringHandler, setStringHandler(cs101.util.StringHandler)

Field Summary
protected  java.io.ObjectInputStream ois
          Where to read data
protected  java.io.ObjectOutputStream oos
          Where to write data
protected  java.net.Socket sock
          Net connection
protected  java.lang.Thread spirit
          Animates this object
protected  StringHandler stringHandler
          Handles input from net
 
Constructor Summary
Client()
          Creates an autonomous client.
Client(StringHandler sh)
          Creates an autonomous client.
Client(java.lang.String hostName, int port)
          Creates an autonomous client.
Client(java.lang.String hostName, int port, StringHandler sh)
          Creates an autonomous client.
 
Method Summary
protected  void connectTo(java.lang.String hostName, int port)
          Opens a connection to a server presumed to be listening on hostName, port.
 void finalize()
          Closes the socket, stops the thread.
 void handleString(java.lang.String s)
          This method is passed the String which has been read by the Client if no other StringHandler has been set.
 void run()
          Reads Strings from the server connection.
 void send(java.lang.String s)
          Use this method to send a String to the server.
 void setStringHandler(StringHandler sh)
          Override default string handling behavior by providing a new StringHandler.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

spirit

protected java.lang.Thread spirit
Animates this object


stringHandler

protected StringHandler stringHandler
Handles input from net


sock

protected java.net.Socket sock
Net connection


ois

protected java.io.ObjectInputStream ois
Where to read data


oos

protected java.io.ObjectOutputStream oos
Where to write data

Constructor Detail

Client

public Client(java.lang.String hostName,
              int port,
              StringHandler sh)
Creates an autonomous client. Send Strings using send; receive Strings as this client's StringHandler (it calls your handleString method).

Parameters:
sh - the StringHandler to handle data this client receives from the net.
hostName - the name of the machine that the server is on
port - the port number on which the server is listening
See Also:
send(java.lang.String), StringHandler

Client

public Client(java.lang.String hostName,
              int port)
Creates an autonomous client. Send Strings using send; receive Strings as this client's StringHandler (it calls your handleString method).

StringHandler may be set later. Otherwise, this object's default method is used.

Parameters:
hostName - the name of the machine that the server is on
port - the port number on which the server is listening
See Also:
send(java.lang.String), setStringHandler(cs101.util.StringHandler)

Client

public Client(StringHandler sh)
Creates an autonomous client. Send Strings using send; receive Strings as this client's StringHandler (it calls your handleString method).

User is prompted for server's hostName and port (using ClientDialog).

Parameters:
sh - the StringHandler to handle data this client receives from the net.
See Also:
StringHandler

Client

public Client()
Creates an autonomous client. Send Strings using send; receive Strings as this client's StringHandler (it calls your handleString method).

StringHandler may be set later. Otherwise, this object's default method is used.

User is prompted for server's hostName and port (using ClientDialog).

See Also:
send(java.lang.String), setStringHandler(cs101.util.StringHandler)
Method Detail

connectTo

protected void connectTo(java.lang.String hostName,
                         int port)
Opens a connection to a server presumed to be listening on hostName, port. Sets up listener thread. Called by constructor; should not be called otherwise.

Parameters:
hostName - the name of the machine that the server is on
port - the port number on which the server is listening

run

public void run()
Reads Strings from the server connection. Called by this object's Thread. Should not be called otherwise.

Specified by:
run in interface java.lang.Runnable

send

public void send(java.lang.String s)
Use this method to send a String to the server.


setStringHandler

public void setStringHandler(StringHandler sh)
Override default string handling behavior by providing a new StringHandler.


handleString

public void handleString(java.lang.String s)
This method is passed the String which has been read by the Client if no other StringHandler has been set. Specialize the client by providing an alternate StringHandler.

Specified by:
handleString in interface StringHandler

finalize

public void finalize()
Closes the socket, stops the thread.


Pig Latin Problem Set Javadocs