Creating Raw Websockets in Spring Boot
date
Jan 24, 2024
slug
raw-websockets-spring
status
Published
tags
SOCKETS
summary
type
Post
Websockets
Websockets allows full bi directional communication between server and client. Basically, client and server both can send messages to one another.
To establish a websocket connections, a HTTP handsake takes place after TCP handsake to upgrade communication from HTTP to Web Socket protocal.

To keep connection alive, web sockets uses hearbeat ping/pong mechanism to keep connection alive.
Spring Websockets
- To create raw websockets in spring boot we need to implement WebSocketConfigurer interface
- WebSocketHandlerRegistry is also a interface that has a single method takes WebSocketHandler instance and paths.
- So we need to create a bean of type WebSocketHandler
- I will use extend
TextWebSocketHandler
that implements WebSocketHandler provided by Spring to implement handler.
- Finally we need to implement WebSocketConfigurer
- We can create a JS client to connect with server for testing.
OUPUT

Spring LOG

References
- Jorge Acetozi - Pro Java Clustering and Scalability_ Building Real-Time Apps with Spring, Cassandra, Redis, WebSocket and RabbitMQ (2017, Apress)