|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object sk.baka.ambient.commons.SocketServer
public abstract class SocketServer
A server which listens on given port and executes tasks when the connection is established. The server is stopped by default.
Constructor Summary | |
---|---|
SocketServer()
|
Method Summary | |
---|---|
void |
close()
|
protected abstract void |
handleRequest(Socket socket,
InputStream in,
OutputStream out)
Handles a request. |
boolean |
isStarted()
Checks if the server is started. |
Thread |
newThread(Runnable r)
|
protected void |
onStopping()
Invoked when the server is being stopped. |
void |
start(int port,
InetAddress bindTo)
Starts the server. |
void |
stop()
Stops the server. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SocketServer()
Method Detail |
---|
public final boolean isStarted()
true
if the server is started, false
otherwise.public final void start(int port, InetAddress bindTo) throws IOException
port
- the port to listen on.bindTo
- listen on this interface. See
ServerSocketFactory.createServerSocket(int, int, InetAddress)
for details.
IOException
- if server failed to start.public final void stop()
protected void onStopping()
public void close()
close
in interface Closeable
public final Thread newThread(Runnable r)
newThread
in interface ThreadFactory
protected abstract void handleRequest(Socket socket, InputStream in, OutputStream out) throws IOException, ServerHttpException, InterruptedException
Thread.isInterrupted()
, terminating ASAP when
interrupted.
socket
- the socket for this request.in
- opened read pipe from the socket.out
- opened write pipe to the socket.
IOException
- if i/o error occurs.
ServerHttpException
- if HTTP error occurs. This error is written as a HTTP
response. If you decide to throw this error then make sure
that nothing was written yet to out
.
InterruptedException
- if interrupted.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |