public class SimpleServer extends Object implements Runnable
The program listens on a socket for client connections. When a client connects, the server creates an instance of RealisationRequest that serves the client.
The RealisationRequest parses the xml structure and sends back corresponding surface string.
The server port can be specified as the first parameter of the program; 50007 is used by default.
Typing exit will terminate the server.
| Constructor and Description |
|---|
SimpleServer(int port)
Construct a new server.
|
SimpleServer(ServerSocket socket)
Construct a server with a pre-allocated socket.
|
| Modifier and Type | Method and Description |
|---|---|
void |
exit()
Exit the program without error.
|
void |
exit(int code)
Exit the program signalling an error code.
|
protected void |
handleClient(Socket socket)
Handle the incoming client connection by constructing
a
RealisationRequest and starting it in a thread. |
static void |
main(String[] args)
The main method that starts the server.
|
void |
run()
Start the server.
|
void |
shutdown()
Perform shutdown routines.
|
void |
terminate()
Terminate the server.
|
public SimpleServer(int port)
throws IOException
port - the port on which to listenIOExceptionpublic SimpleServer(ServerSocket socket) throws IOException
IOExceptionpublic void terminate()
run() method.public void run()
The server will listen on the port specified at construction
until terminated by calling the terminate() method.
Note that the exit() and exit(int)
methods will terminate the program by calling System.exit().
protected void handleClient(Socket socket)
RealisationRequest and starting it in a thread.socket - the socket on which the client connectedpublic void shutdown()
public void exit()
public void exit(int code)
code - Error code; 0 means no errorpublic static void main(String[] args)
The program takes one optional parameter, which is the port number on which to listen. The default value is 50007.
Once the program starts, it can be terminated by typing the command 'exit'
args - Program argumentsCopyright © 2020. All Rights Reserved.