The SockJS
library provides cross-browser JavaScript API to enable low latency, cross-domain communication between the browser and server. It aims to support the following goals:
- Instead of using the
WebSocket
instance, theSockJS
instance is used - It provides APIs that are close to the
WebSocket
API, both for server as well as client-side APIs - Faster communication support
- JavaScript for client side
- It comes with some chosen protocols that support cross-domain communication
The following code snippet shows us how to enable the SockJS
library support for WebSocketConfigure
:
@Override public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) { registry.addHandler(myHandler(), "/myHandler_sockjs").setAllowedOrigins("*").withSockJS(); }
We can also configure in XML as follows:
<websocket:handlers> <websocket:mapping path="/myHandler" handler="myHandler_sockjs"/> <websocket:sockjs/> </websocket:handlers>
We can update the Capital...