WebSocketListener Class

Instances 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());
            }
        }
    }
  

Constructors

WebSocketListener( HttpServletRequest request, HttpServletResponse response )

Public Methods

onConnect( ) returns void
Called whenever a new WebSocket connection is established.
onDisconnect( 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.
send( String str ) returns void
Used to send a text message to the client.
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.
close( int code, String reason ) returns void
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.
getLocalAddress( ) returns String
getLocalHostName( ) returns String
getLocalPort( ) returns int
getRemoteAddress( ) returns String
getRemoteHostName( ) returns String
getRemotePort( ) returns int
getCertificates( ) returns java.security.cert.X509Certificate[]
getCookies( ) returns Cookie[]
getExtensions( ) returns java.util.Enumeration<String>
getUserPrincipal( ) returns java.security.Principal
isSecure( ) returns boolean
isUserInRole( String role ) returns boolean
getHeader( String name ) returns String
getHeaders( ) returns java.util.Map<String, java.util.List<String>>
getHeaders( String name ) returns java.util.List<String>
getLocale( ) returns java.util.Locale
getLocales( ) returns java.util.Enumeration<java.util.Locale>
getParameterMap( ) returns java.util.Map<String, String[]>
getProtocolVersion( ) returns String
hasSubProtocol( String test ) returns boolean
getSubProtocols( ) returns java.util.List<String>