WebSocketListener Class

Used to process WebSocket requests. Instances of this class are created within the HttpServlet.processRequest() method. Example:

    public class WebSocketTest extends HttpServlet {
        
        public WebSocketTest() {}
        
        public void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, java.io.IOException {  
        
            if (request.isWebSocket()){
                new WebSocketListener(ws, request, response){
                    public void onConnect(){
                        send("Hello There!");
                    }
                    public void onText(String str){
                        send("Message recieved at " + new java.util.Date());
                    }
                    public void onDisconnect(int statusCode, String reason){
                        send("Goodbye!");
                    }
                };
                return;
            }
        }
    }
 

Constructors

public WebSocketListener( javaxt.http.servlet.HttpServletRequest request, javaxt.http.servlet.HttpServletResponse response )

Methods

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.
onBinary( java.nio.ByteBuffer buf ) returns void
Called whenever a client sends binary data to the WebSocket.
onConnect( ) returns void
Called whenever a new WebSocket connection is established.
onDisconnect( int statusCode, String reason, boolean remote ) 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.
send( String str ) returns void
Used to send a text message to the client.