Order the Book

Class EchoServer

java.lang.Object
  |
  +--NetworkServer
        |
        +--EchoServer
Direct Known Subclasses:
ThreadedEchoServer

public class EchoServer
extends NetworkServer

A simple HTTP server that generates a Web page showing all of the data that it received from the Web client (usually a browser). To use this, start it on the system of your choice, supplying a port number if you want something other than port 8088. Call this system server.com. Next, start a Web browser on the same or a different system, and connect to http://server.com:8088/whatever. The resultant Web page will show the data that your browser sent. For debugging in servlet or CGI programming, specify http://server.com:8088/whatever as the ACTION of your HTML form. You can send GET or POST data; either way, the resultant page will show what your browser sent.

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.


Field Summary
protected  int maxRequestLines
           
protected  String serverName
           
 
Constructor Summary
EchoServer(int port, int maxConnections)
           
 
Method Summary
 void handleConnection(Socket server)
          Overrides the NetworkServer handleConnection method to read each line of data received, save it into an array of strings, then send it back embedded inside a PRE element in an HTML page.
static void main(String[] args)
          Supply a port number as a command-line argument.
 
Methods inherited from class NetworkServer
getMaxConnections, getPort, listen, setMaxConnections, setPort
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

maxRequestLines

protected int maxRequestLines

serverName

protected String serverName
Constructor Detail

EchoServer

public EchoServer(int port,
                  int maxConnections)
Method Detail

main

public static void main(String[] args)
Supply a port number as a command-line argument. Otherwise port 8088 will be used.

handleConnection

public void handleConnection(Socket server)
                      throws IOException
Overrides the NetworkServer handleConnection method to read each line of data received, save it into an array of strings, then send it back embedded inside a PRE element in an HTML page.
Overrides:
handleConnection in class NetworkServer

Order the Book

Order
CSAJSP @ amazon.com

Return to Top-Level Source Code Archive