|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.tootallnate.websocket.WebSocketAdapter
net.tootallnate.websocket.WebSocketServer
public abstract class WebSocketServer
WebSocketServer is an abstract class that only takes care of the HTTP handshake portion of WebSockets. It's up to a subclass to add functionality/purpose to the server.
| Constructor Summary | |
|---|---|
WebSocketServer()
Nullary constructor. |
|
WebSocketServer(java.net.InetSocketAddress address)
Creates a WebSocketServer that will attempt to listen on port port. |
|
WebSocketServer(java.net.InetSocketAddress address,
Draft draft)
Creates a WebSocketServer that will attempt to listen on port port, and comply with Draft version draft. |
|
| Method Summary | |
|---|---|
java.util.Set<WebSocket> |
connections()
Returns a WebSocket[] of currently connected clients. |
java.net.InetSocketAddress |
getAddress()
|
Draft |
getDraft()
|
protected java.lang.String |
getFlashSecurityPolicy()
Gets the XML string that should be returned if a client requests a Flash security policy. |
int |
getPort()
Gets the port number that this server listens on. |
abstract void |
onClientClose(WebSocket conn)
|
abstract void |
onClientMessage(WebSocket conn,
java.lang.String message)
|
abstract void |
onClientOpen(WebSocket conn)
|
void |
onClose(WebSocket conn)
Called after WebSocket#close is explicity called, or when the other end of the WebSocket connection is closed. |
abstract void |
onError(WebSocket conn,
java.lang.Exception ex)
|
void |
onMessage(WebSocket conn,
java.lang.String message)
Called when an entire text frame has been recieved. |
void |
onOpen(WebSocket conn)
Called after onHandshakeRecieved returns true. |
void |
onWriteDemand(WebSocket conn)
|
void |
run()
|
void |
sendToAll(java.lang.String text)
Sends text to all currently connected WebSocket clients. |
void |
sendToAllExcept(java.util.Set<WebSocket> connections,
java.lang.String text)
Sends text to all currently connected WebSocket clients, except for those found in the Set connections. |
void |
sendToAllExcept(WebSocket connection,
java.lang.String text)
Sends text to all currently connected WebSocket clients, except for the specified connection. |
void |
setAddress(java.net.InetSocketAddress address)
Sets the port that this WebSocketServer should listen on. |
void |
start()
Starts the server thread that binds to the currently set port number and listeners for WebSocket connection requests. |
void |
stop()
Closes all connected clients sockets, then closes the underlying ServerSocketChannel, effectively killing the server socket thread and freeing the port the server was bound to. |
| Methods inherited from class net.tootallnate.websocket.WebSocketAdapter |
|---|
getFlashPolicy, onHandshakeRecievedAsClient, onHandshakeRecievedAsServer, onMessage, onPing, onPong |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public WebSocketServer()
throws java.net.UnknownHostException
java.net.UnknownHostExceptionpublic WebSocketServer(java.net.InetSocketAddress address)
port - The port number this server should listen on.
public WebSocketServer(java.net.InetSocketAddress address,
Draft draft)
port - The port number this server should listen on.draft - The version of the WebSocket protocol that this server
instance should comply to.| Method Detail |
|---|
public void start()
java.lang.IllegalStateException
public void stop()
throws java.io.IOException
java.io.IOException - When socket related I/O errors occur.
public void sendToAll(java.lang.String text)
throws java.lang.InterruptedException
text - The String to send across the network.
java.io.IOException - When socket related I/O errors occur.
java.lang.InterruptedException
public void sendToAllExcept(WebSocket connection,
java.lang.String text)
throws java.lang.InterruptedException
connection - The WebSocket connection to ignore.text - The String to send to every connection except connection.
java.io.IOException - When socket related I/O errors occur.
java.lang.InterruptedException
public void sendToAllExcept(java.util.Set<WebSocket> connections,
java.lang.String text)
throws java.lang.InterruptedException
connections - text -
java.io.IOException - When socket related I/O errors occur.
java.lang.InterruptedExceptionpublic java.util.Set<WebSocket> connections()
public void setAddress(java.net.InetSocketAddress address)
port - The port number to listen on.public java.net.InetSocketAddress getAddress()
public int getPort()
public Draft getDraft()
public void run()
run in interface java.lang.Runnableprotected java.lang.String getFlashSecurityPolicy()
public void onMessage(WebSocket conn,
java.lang.String message)
onMessage in class WebSocketAdapterconn - The WebSocket instance this event is occuring on.message - The UTF-8 decoded message that was recieved.public void onOpen(WebSocket conn)
onOpen in class WebSocketAdapterconn - The WebSocket instance this event is occuring on.public void onClose(WebSocket conn)
onClose in class WebSocketAdapterconn - The WebSocket instance this event is occuring on.public void onWriteDemand(WebSocket conn)
public abstract void onClientOpen(WebSocket conn)
public abstract void onClientClose(WebSocket conn)
public abstract void onClientMessage(WebSocket conn,
java.lang.String message)
public abstract void onError(WebSocket conn,
java.lang.Exception ex)
onError in class WebSocketAdapterconn - may be null if the error does not belong to a single connection
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||