WebSocket-SpringBoot | Getting Started
For building and running the application you need:
You can build the application by using the maven build command like so:
mvn clean install -DskipTests
Connecting to the WebSocket/ServerEndpoint
After cloning the repo on your local machine, start the SpringBoot application.
The application will be started on
http://localhost:8080/. You can configure and start the application on a different post.
The application will expose two endpoints.
i. WebSocket (ws) Endpoint
ii. HTTP Endpoint
You need to establish a WS connection on
ws://localhost:8080/webSocketwith your websocket client.
Once you establish a connection to the WebSocket endpoint, you will start listening to any messages that get broadcasted to the listeners.
Broadcasting Messages to WebSocket Listeners
- To broadcast the message, you need to use the
- A query parameter
messagehas been set up to broadcast messages.
- Make a HTTP
http://localhost:8080/broadcast?message=Hello World, and your socket listeners will receive the message
Hello Worldon their clients.
WebSocket Simple Client
You can also use this WebSocket Client. Download the
WebSocket-Client.zip from HERE.
If you want to learn how to create WebSocket in Spring Boot with the better understanding, you can check out a step-by-step tutorial on my blog HERE