A simple yet powerful demonstration of WebSocket communication in Java, featuring both server-side and client-side implementations. Perfect for learning real-time bidirectional communication between web browsers and Java applications!
- 🔌 Full-Stack WebSocket Implementation - Complete server and client examples
- 🌐 Browser-Based Client - Interactive web interface using JavaScript
- ☕ Pure Java Client - Standalone Java client for programmatic access
- 🚀 Embedded Jetty Server - Quick start with Maven plugin
- 📦 Minimal Dependencies - Clean, focused codebase using standard APIs
- 🎯 Production-Ready - Built with Java EE WebSocket API (JSR 356)
- Java 8+ - Modern Java features
- Maven - Dependency management and build automation
- Jetty 9.4 - Lightweight, embedded web server
- Tyrus - Reference implementation of Java API for WebSocket
- jQuery - Simplified DOM manipulation for web client
- JSP - Dynamic web page generation
- Java Development Kit (JDK) 8 or higher
- Apache Maven 3.x
- A modern web browser (Chrome, Firefox, Safari, Edge)
mvn jetty:runThe server will start on http://localhost:8080/hello-websocket
Open your browser and navigate to:
http://localhost:8080/hello-websocket/index.jsp
Click the "Send Message" button to send a WebSocket message and see real-time responses!
Execute the Java client programmatically:
pkg.WebSocketClientMain.main()Press Ctrl + C in the terminal where the server is running.
hello-java-websocket/
├── src/
│ └── main/
│ ├── java/ # Java source files (server & client)
│ └── webapp/
│ └── index.jsp # Interactive web client
├── pom.xml # Maven configuration
├── LICENSE # Apache License 2.0
└── README.md # This file
This project is ideal for:
- 📚 Learning WebSocket Technology - Understand bidirectional communication
- 🔧 Prototyping Real-Time Applications - Chat apps, live notifications, dashboards
- 🧪 Testing WebSocket Endpoints - Validate server implementations
- 📖 Educational Purposes - Teaching material for web development courses
- 🏗️ Foundation for Larger Projects - Starting point for complex real-time systems
Experience instant, bidirectional data flow between client and server without polling or long-polling overhead.
Choose between browser-based JavaScript client or standalone Java client based on your needs.
Clean, well-structured code makes it simple to add custom message handlers, authentication, or business logic.
Built on Java EE standard WebSocket API (JSR 356), ensuring compatibility and best practices.
The WebSocket endpoint is configured in pom.xml:
- Port: 8080
- Context Path:
/hello-websocket - WebSocket Endpoint:
/helloendpoint
Full WebSocket URL: ws://localhost:8080/hello-websocket/helloendpoint
Contributions are welcome! Feel free to:
- 🐛 Report bugs
- 💡 Suggest new features
- 🔧 Submit pull requests
- 📖 Improve documentation
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
If you find this project helpful, please consider giving it a ⭐ star on GitHub!
Happy Coding! 🎉