|
JavaXT
|
|
WebSocketListener ClassInstances of this class are used to process WebSocket requests. Example:
public class MyServlet extends HttpServlet {
public MyServlet() {}
public void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, java.io.IOException {
if (request.isWebSocket()){
new WebSocketListener(request, response){
public void onConnect(){
send("Hello There!");
}
public void onText(String str){
//System.out.println(str);
send("Message recieved at " + new java.util.Date());
}
public void onDisconnect(int statusCode, String reason, boolean remote){
//System.out.println("Goodbye...");
}
};
}
else{ //standard http request
response.write("Hello, the time is now " + new java.util.Date());
}
}
}
ConstructorsPublic MethodsonDisconnect( int statusCode, String reason ) returns void Called whenever a WebSocket connection is terminated. onText( String str ) returns void Called whenever a client sends a text message to the WebSocket. close( ) returns void Sends a websocket Close frame, with a normal status code and no reason phrase. This will enqueue a graceful close to the remote endpoint. disconnect( ) returns void Issues a harsh disconnect of the underlying connection. This will terminate the connection, without sending a websocket close frame. getURI( ) returns java.net.URI Returns the URI used to establish the WebSocket connection. |
|