Creating a WebSocketHandler

The creation of a WebSocketHandler interface can be done either by implementing the WebSocketHandler interface, or by extending from TextWebSocketHandler or BinaryWebSocketHandler, as we have done in the following code snippet:

public class MyWebSocketHandler extends TextWebSocketHandler{ 
@Override 
   public void handleTextMessage(WebSocketSession session,     
     TextMessage message) 
  { 
    // code goes here 
  } 
} 

The WebSocketDecorator class can be used to decorate the WebSocketHandler interface. Spring provides some decorator classes to handle exceptions, logging mechanism, and handling binary. The ExceptionWebSocketHandler class is an Exception handling WebSocketHandlerDecorator, which helps in handling all instances of Throwable. The LoggingWebSocketHandlerDecorator class adds logging to the events that take place in the life cycle of WebSocket.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.114.142