net.tootallnate.websocket
Class WebSocketAdapter

java.lang.Object
  extended by net.tootallnate.websocket.WebSocketAdapter
Direct Known Subclasses:
WebSocketClient, WebSocketServer

public abstract class WebSocketAdapter
extends java.lang.Object


Constructor Summary
WebSocketAdapter()
           
 
Method Summary
 java.lang.String getFlashPolicy(WebSocket conn)
          Gets the XML string that should be returned if a client requests a Flash security policy.
 void onClose(WebSocket conn)
          Called after WebSocket#close is explicity called, or when the other end of the WebSocket connection is closed.
 void onError(WebSocket conn, java.lang.Exception ex)
           
 boolean onHandshakeRecievedAsClient(WebSocket conn, Handshakedata request, Handshakedata response)
           
 HandshakeBuilder onHandshakeRecievedAsServer(WebSocket conn, Draft draft, Handshakedata request)
          Called when the socket connection is first established, and the WebSocket handshake has been recieved.
 void onMessage(WebSocket conn, byte[] blob)
           
 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 onPing(WebSocket conn, Framedata f)
           
 void onPong(WebSocket conn, Framedata f)
           
 void onWriteDemand(WebSocket conn)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

WebSocketAdapter

public WebSocketAdapter()
Method Detail

onHandshakeRecievedAsServer

public HandshakeBuilder onHandshakeRecievedAsServer(WebSocket conn,
                                                    Draft draft,
                                                    Handshakedata request)
                                             throws java.io.IOException
Called when the socket connection is first established, and the WebSocket handshake has been recieved.

Throws:
java.io.IOException

onHandshakeRecievedAsClient

public boolean onHandshakeRecievedAsClient(WebSocket conn,
                                           Handshakedata request,
                                           Handshakedata response)
                                    throws java.io.IOException
Throws:
java.io.IOException

onMessage

public void onMessage(WebSocket conn,
                      java.lang.String message)
Called when an entire text frame has been recieved. Do whatever you want here...

Parameters:
conn - The WebSocket instance this event is occuring on.
message - The UTF-8 decoded message that was recieved.

onOpen

public void onOpen(WebSocket conn)
Called after onHandshakeRecieved returns true. Indicates that a complete WebSocket connection has been established, and we are ready to send/recieve data.

Parameters:
conn - The WebSocket instance this event is occuring on.

onClose

public void onClose(WebSocket conn)
Called after WebSocket#close is explicity called, or when the other end of the WebSocket connection is closed.

Parameters:
conn - The WebSocket instance this event is occuring on.

onMessage

public void onMessage(WebSocket conn,
                      byte[] blob)

onPing

public void onPing(WebSocket conn,
                   Framedata f)

onPong

public void onPong(WebSocket conn,
                   Framedata f)

getFlashPolicy

public java.lang.String getFlashPolicy(WebSocket conn)
Gets the XML string that should be returned if a client requests a Flash security policy. The default implementation allows access from all remote domains, but only on the port that this WebSocketServer is listening on. This is specifically implemented for gitime's WebSocket client for Flash: http://github.com/gimite/web-socket-js

Returns:
An XML String that comforms to Flash's security policy. You MUST not include the null char at the end, it is appended automatically.

onError

public void onError(WebSocket conn,
                    java.lang.Exception ex)

onWriteDemand

public void onWriteDemand(WebSocket conn)