Skip to content

oyahiroki/hello-java-websocket

Repository files navigation

🚀 Hello Java WebSocket

License Java Maven

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!

✨ Features

  • 🔌 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)

🛠️ Technology Stack

  • 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

📋 Prerequisites

  • Java Development Kit (JDK) 8 or higher
  • Apache Maven 3.x
  • A modern web browser (Chrome, Firefox, Safari, Edge)

🚀 Quick Start

1️⃣ Start the WebSocket Server

mvn jetty:run

The server will start on http://localhost:8080/hello-websocket

2️⃣ Connect with Browser Client

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!

3️⃣ Run Java Client (Alternative)

Execute the Java client programmatically:

pkg.WebSocketClientMain.main()

🛑 Stop the Server

Press Ctrl + C in the terminal where the server is running.

📁 Project Structure

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

🎯 Use Cases

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

🌟 Key Highlights

Real-Time Communication

Experience instant, bidirectional data flow between client and server without polling or long-polling overhead.

Multiple Client Options

Choose between browser-based JavaScript client or standalone Java client based on your needs.

Easy to Extend

Clean, well-structured code makes it simple to add custom message handlers, authentication, or business logic.

Production-Grade APIs

Built on Java EE standard WebSocket API (JSR 356), ensuring compatibility and best practices.

📝 Configuration

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

🤝 Contributing

Contributions are welcome! Feel free to:

  • 🐛 Report bugs
  • 💡 Suggest new features
  • 🔧 Submit pull requests
  • 📖 Improve documentation

📄 License

This project is licensed under the Apache License 2.0 - see the LICENSE file for details.

🔗 Resources

💬 Support

If you find this project helpful, please consider giving it a ⭐ star on GitHub!


Happy Coding! 🎉

About

WebSocket Java Server & Java Client

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages