|
CS101 Package Problem Set Javadocs | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object cs101.net.Client
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
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 |
protected java.lang.Thread spirit
protected StringHandler stringHandler
protected java.net.Socket sock
protected java.io.ObjectInputStream ois
protected java.io.ObjectOutputStream oos
Constructor Detail |
public Client(java.lang.String hostName, int port, StringHandler sh)
sh
- the StringHandler to handle data this client receives from the net.hostName
- the name of the machine that the server is onport
- the port number on which the server is listeningsend(java.lang.String)
,
StringHandler
public Client(java.lang.String hostName, int port)
StringHandler may be set later. Otherwise, this object's default method is used.
hostName
- the name of the machine that the server is onport
- the port number on which the server is listeningsend(java.lang.String)
,
setStringHandler(cs101.util.StringHandler)
public Client(StringHandler sh)
User is prompted for server's hostName and port (using ClientDialog).
sh
- the StringHandler to handle data this client receives from the net.StringHandler
public Client()
StringHandler may be set later. Otherwise, this object's default method is used.
User is prompted for server's hostName and port (using ClientDialog).
send(java.lang.String)
,
setStringHandler(cs101.util.StringHandler)
Method Detail |
protected void connectTo(java.lang.String hostName, int port)
hostName
- the name of the machine that the server is onport
- the port number on which the server is listeningpublic void run()
run
in interface java.lang.Runnable
public void send(java.lang.String s)
public void setStringHandler(StringHandler sh)
public void handleString(java.lang.String s)
handleString
in interface StringHandler
public void finalize()
|
CS101 Package Problem Set Javadocs | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |