|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectnet.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.
| Nested Class Summary | |
|---|---|
static class |
WebSocketListener.Draft
Enum for WebSocket Draft |
| Constructor Summary | |
|---|---|
WebSocketServer()
Nullary constructor. |
|
WebSocketServer(int port,
WebSocketListener.Draft draft)
Creates a WebSocketServer that will attempt to listen on port port. |
|
| Method Summary | |
|---|---|
WebSocket[] |
connections()
Returns a WebSocket[] of currently connected clients. |
WebSocketListener.Draft |
getDraft()
Called to retrieve the Draft of this listener. |
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. |
boolean |
onHandshakeRecieved(WebSocket conn,
java.lang.String handshake,
byte[] key3)
Called by a WebSocket instance when a client connection has
finished sending a handshake. |
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 |
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 |
setPort(int port)
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 java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public WebSocketServer()
public WebSocketServer(int port,
WebSocketListener.Draft draft)
port - The port number this server should listen on.| Method Detail |
|---|
public void start()
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.io.IOException
text - The String to send across the network.
java.io.IOException - When socket related I/O errors occur.
public void sendToAllExcept(WebSocket connection,
java.lang.String text)
throws java.io.IOException
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.
public void sendToAllExcept(java.util.Set<WebSocket> connections,
java.lang.String text)
throws java.io.IOException
connections - text -
java.io.IOException - When socket related I/O errors occur.public WebSocket[] connections()
public void setPort(int port)
port - The port number to listen on.public int getPort()
public WebSocketListener.Draft getDraft()
public void run()
run in interface java.lang.Runnableprotected java.lang.String getFlashSecurityPolicy()
public boolean onHandshakeRecieved(WebSocket conn,
java.lang.String handshake,
byte[] key3)
throws java.io.IOException,
java.security.NoSuchAlgorithmException
WebSocket instance when a client connection has
finished sending a handshake. This method verifies that the handshake is
a valid WebSocket cliend request. Then sends a WebSocket server handshake
if it is valid, or closes the connection if it is not.
conn - The WebSocket instance who's handshake has been recieved.handshake - The entire UTF-8 decoded handshake from the connection.
java.io.IOException - When socket related I/O errors occur.
java.security.NoSuchAlgorithmException
public void onMessage(WebSocket conn,
java.lang.String message)
conn - The WebSocket instance this event is occuring on.message - The UTF-8 decoded message that was recieved.public void onOpen(WebSocket conn)
conn - The WebSocket instance this event is occuring on.public void onClose(WebSocket conn)
conn - The WebSocket instance this event is occuring on.public abstract void onClientOpen(WebSocket conn)
public abstract void onClientClose(WebSocket conn)
public abstract void onClientMessage(WebSocket conn,
java.lang.String message)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||