Class NetworkClient
java.lang.Object
|
+--NetworkClient
- Direct Known Subclasses:
- HttpClient
- public class NetworkClient
- extends Object
A starting point for network clients. You'll need to
override handleConnection, but in many cases
connect can remain unchanged. It uses
SocketUtil to simplify the creation of the
PrintWriter and BufferedReader.
Taken from Core Servlets and JavaServer Pages
from Prentice Hall and Sun Microsystems Press,
http://www.coreservlets.com/.
© 2000 Marty Hall; may be freely used or adapted.
|
Method Summary |
void |
connect()
Establishes the connection, then passes the socket
to handleConnection. |
String |
getHost()
The hostname of the server we're contacting. |
int |
getPort()
The port connection will be made on. |
protected void |
handleConnection(Socket client)
This is the method you will override when
making a network client for your task. |
| Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
host
protected String host
port
protected int port
NetworkClient
public NetworkClient(String host,
int port)
- Register host and port. The connection won't
actually be established until you call
connect.
connect
public void connect()
- Establishes the connection, then passes the socket
to handleConnection.
handleConnection
protected void handleConnection(Socket client)
throws IOException
- This is the method you will override when
making a network client for your task.
The default version sends a single line
("Generic Network Client") to the server,
reads one line of response, prints it, then exits.
getHost
public String getHost()
- The hostname of the server we're contacting.
getPort
public int getPort()
- The port connection will be made on.
 |
|---|
| CSAJSP @ amazon.com |
|---|