Web Sockets
WebSocket is a computer communications protocol, providing full-duplex communication channels over a single TCP connection
Websockets are used in case of real-time interactive applications
WebSocket is a thin, lightweight layer above TCP. This makes it suitable for using “subprotocols” to embed messages
using STOMP(Streaming Text Oriented Messaging Protocol) messaging with Spring to create an interactive web application. STOMP is a subprotocol operating on top of the lower-level WebSocket.
Configure Spring for STOMP messaging
@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
@Override
public void configureMessageBroker(MessageBrokerRegistry config) {
config.enableSimpleBroker("/topic");
config.setApplicationDestinationPrefixes("/app");
}
@Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/gs-guide-websocket").withSockJS();
}
}
the connection between a server and a cient need two sockets, server socket that is created using spring boot framework and the client socket is created using javascript.