public class SimpleServer extends Object
Modifier and Type | Class and Description |
---|---|
static class |
SimpleServer.SimpleServerException
An exception type that represents server-related runtime errors.
|
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_PORT
Default port to listen for requests.
|
Constructor and Description |
---|
SimpleServer(int port)
Constructs a new server that will listen on the given port.
|
SimpleServer(SimpleServerListener webApp)
Constructs a new server that will listen on a default port, with the given
listener to be notified as each request comes in.
|
SimpleServer(SimpleServerListener webApp,
int port)
Constructs a new server that will listen on the given port, with the given
listener to be notified as each request comes in.
|
Modifier and Type | Method and Description |
---|---|
int |
getPort()
Returns the port on which this server will listen.
|
boolean |
isRunning()
Returns whether the server is currently active and listening for HTTP requests,
which will be true after start() is called.
|
boolean |
portIsAvailable()
Returns true if this server's port is available for listening.
|
static boolean |
portIsAvailable(int port)
Returns true if the given port is available for listening.
|
HashMap<String,String> |
sessionData(Request request)
Returns all data associated with the given request's session.
|
void |
sessionEnd(Request request)
Ends any active session for the given request, clearing its session data.
|
boolean |
sessionIsInProgress(Request request)
Returns whether the given request contains an active session.
|
void |
sessionStart(Request request)
Begins an active session for the given request, with empty session data.
|
void |
start()
Starts a server on the given port.
|
void |
stop()
Stops the server so that it will no longer listen to HTTP requests.
|
String |
toString()
Returns a string representation of this server.
|
public static final int DEFAULT_PORT
public SimpleServer(int port)
port
- the port to listen on, up to 65535public SimpleServer(SimpleServerListener webApp)
webApp
- listener to notify on each requestpublic SimpleServer(SimpleServerListener webApp, int port)
webApp
- listener to notify on each requestport
- the port to listen on, up to 65535public int getPort()
public boolean isRunning()
public boolean portIsAvailable()
public static boolean portIsAvailable(int port)
public boolean sessionIsInProgress(Request request)
public HashMap<String,String> sessionData(Request request)
public void sessionEnd(Request request)
public void sessionStart(Request request)
public void start()
public void stop()