Merged many of the changes from the first attempt at an HTML5 Websocket implementation. Focused on the ones that didn't change the behavior of the web server.

This commit is contained in:
wcrisman
2014-12-07 16:12:29 -08:00
parent 46df41d433
commit 2adcfad863
13 changed files with 525 additions and 4 deletions

View File

@@ -0,0 +1,67 @@
package com.foundation.web.interfaces;
/**
* The base class for a websocket handler passed to the IConnectionContext object when converting an HTTP connection into a websocket.
*/
public abstract class WebsocketHandler {
/** The websocket connection reference. */
private IConnectionContext connection;
/**
* WebsocketHandler constructor.
* @param connection The websocket connection reference.
*/
public WebsocketHandler(IConnectionContext connection) {
this.connection = connection;
}//WebsocketHandler()//
/**
* Receives a text message from the client.
* @param message The message received.
*/
public abstract void receiveTextMessage(String message);
/**
* Receives a binary message from the client.
* @param message The message received.
*/
public abstract void receiveBinaryMessage(byte[] message);
/**
* Receives a pong control message from the client (in reponse to a ping from the server).
*/
public void receivePong() {
//Does nothing.//
}//receivePong()//
/**
* Sends a text message to the client without blocking.
* <br/>This is a thread safe call.
* @param message The message to be sent.
*/
public void sendTextMessage(String message) {
connection.sendWebsocketMessage(message);
}//sendTextMessage()//
/**
* Sends a binary message to the client without blocking.
* <br/>This is a thread safe call.
* @param message The message to be sent.
*/
public void sendBinaryMessage(byte[] message) {
connection.sendWebsocketMessage(message);
}//sendBinaryMessage()//
/**
* Sends a streamed message to the client without blocking.
* <br/>This is a thread safe call.
* @param message The message to be sent.
*/
public void sendStreamedMessage(IStreamedWebsocketMessage message) {
connection.sendWebsocketMessage(message);
}//sendStreamedMessage()//
/**
* Sends a ping control message to the client which will respond with a pong control message.
*/
public void sendPing() {
connection.sendWebsocketPing();
}//sendPing()//
/**
* Called by the connection when it is closed for any reason.
*/
public abstract void connectionClosed();
}//WebsocketHandler//