A simple broadcast server that sends messages to all connected clients in real-time using WebSocket and STOMP.
This project is a broadcast server built using Spring Boot and WebSocket with the STOMP protocol. It is packaged as a single executable JAR that can run in two modes: as a server that listens for incoming client connections, or as a client that connects to the server and sends messages. Any message sent by a client is broadcast to all other connected clients in real-time.
- Java 21.0.11
- Spring Boot 4.0.6
- Spring WebSocket (STOMP)
- Start a WebSocket broadcast server.
- Connect to the server as a client.
- Broadcast messages to all connected clients in real-time.
- Handle multiple simultaneous client connections.
- Graceful handling of client connect and disconnect events.
To run this project locally, you'll need Java 21 or higher.
-
Clone the repository:
git clone https://github.com/krisnaajiep/springboot-broadcast-server.git
-
Navigate to the project directory:
cd springboot-broadcast-server -
Build the project using Maven:
mvn clean package -DskipTests
The application is packaged as a single JAR that runs in two modes depending on the argument passed.
Run the JAR with the start argument to start the broadcast server:
java -jar target/springboot-broadcast-server-1.0.0.jar startThe server will start and listen for incoming WebSocket connections:
Broadcast server starting on port 8080
Open a new terminal and run the JAR with the connect argument to connect as a client:
java -jar target/springboot-broadcast-server-1.0.0.jar connectYou will be prompted to enter your name, then connected to the server:
Connecting to ws://localhost:8080/broadcast-server
Enter your name: Client
Welcome to the broadcast server Client!
Write something to send your message:
Hello everyone!
(You)[2026-06-09 10:00:00]: Hello everyone!
Any message you send will be broadcast to all connected clients. Messages from other clients will appear as:
(Other)[2026-06-09 10:00:05]: Hello from other client!
To disconnect, press Ctrl+C.
Open as many terminals as needed and run the connect command in each one to simulate multiple clients broadcasting to each other.
Project is: complete.
This project was inspired by roadmap.sh.
This project is licensed under the MIT License - see the LICENSE file for details.