11package net .tootallnate .websocket ;
22
3- import java . io . IOException ;
3+ import net . tootallnate . websocket . exeptions . InvalidDataException ;
44
55/**
66 * Implemented by <tt>WebSocketClient</tt> and <tt>WebSocketServer</tt>.
77 * The methods within are called by <tt>WebSocket</tt>.
8- *
9- * @author Nathan Rajlich
8+ * Almost every method takes a first parameter conn which represents the source of the respective event.
109 */
11- interface WebSocketListener {
10+ public interface WebSocketListener {
1211
1312 /**
14- * Called when the socket connection is first established, and the WebSocket
15- * handshake has been recieved.
13+ * Called on the server side when the socket connection is first established, and the WebSocket
14+ * handshake has been received.
15+ *
16+ * @param draft
17+ * The protocol draft the client uses to connect
18+ * @param request
19+ * The opening http message send by the client. Can be used to access additional fields like cookies.
20+ * @return Returns an incomplete handshake containing all optional fields
21+ * @throws InvalidDataException
22+ * Throwing this exception will cause this handshake to be rejected
1623 */
17- public HandshakeBuilder onHandshakeRecievedAsServer ( WebSocket conn , Draft draft , Handshakedata request ) throws IOException ;
18- public boolean onHandshakeRecievedAsClient ( WebSocket conn , Handshakedata request , Handshakedata response ) throws IOException ;
24+ public HandshakeBuilder onHandshakeRecievedAsServer ( WebSocket conn , Draft draft , Handshakedata request ) throws InvalidDataException ;
25+ /**
26+ * Called on the client side when the socket connection is first established, and the WebSocket
27+ * handshake response has been received.
28+ *
29+ * @param request
30+ * The handshake initially send out to the server by this websocket.
31+ * @param response
32+ * The handshake the server sent in response to the request.
33+ * @throws InvalidDataException
34+ * Allows the client to reject the connection with the server in respect of its handshake response.
35+ */
36+ public void onHandshakeRecievedAsClient ( WebSocket conn , Handshakedata request , Handshakedata response ) throws InvalidDataException ;
1937
2038 /**
21- * Called when an entire text frame has been recieved . Do whatever you want
39+ * Called when an entire text frame has been received . Do whatever you want
2240 * here...
2341 *
2442 * @param conn
25- * The <tt>WebSocket</tt> instance this event is occuring on.
43+ * The <tt>WebSocket</tt> instance this event is occurring on.
2644 * @param message
27- * The UTF-8 decoded message that was recieved .
45+ * The UTF-8 decoded message that was received .
2846 */
2947 public void onMessage ( WebSocket conn , String message );
3048
49+ /**
50+ * Called when an entire binary frame has been received. Do whatever you want
51+ * here...
52+ *
53+ * @param conn
54+ * The <tt>WebSocket</tt> instance this event is occurring on.
55+ * @param message
56+ * The binary message that was received.
57+ */
3158 public void onMessage ( WebSocket conn , byte [] blob );
3259
3360 /**
@@ -49,13 +76,36 @@ interface WebSocketListener {
4976 */
5077 public void onClose ( WebSocket conn , int code , String reason , boolean remote );
5178
79+ /**
80+ * Called if an exception worth noting occurred.
81+ * If an error causes the connection to fail onClose will be called additionally afterwards.
82+ *
83+ * @param ex
84+ * The exception that occurred. <br>
85+ * Might be null if the exception is not related to any specific connection. For example if the server port could not be bound.
86+ */
5287 public void onError ( WebSocket conn , Exception ex );
5388
89+ /**
90+ * Called a ping frame has been received.
91+ * This method must send a corresponding pong by itself.
92+ *
93+ * @param f
94+ * The ping frame. Control frames may contain payload.
95+ */
5496 public void onPing ( WebSocket conn , Framedata f );
5597
98+ /**
99+ * Called when a pong frame is received.
100+ **/
56101 public void onPong ( WebSocket conn , Framedata f );
57102
103+ /**
104+ * Gets the XML string that should be returned if a client requests a Flash
105+ * security policy.
106+ */
58107 public String getFlashPolicy ( WebSocket conn );
59108
109+ /** This method is used to inform the selector thread that there is data queued to be written to the socket. */
60110 public void onWriteDemand ( WebSocket conn );
61111}
0 commit comments