- Notifications
You must be signed in to change notification settings - Fork1
JSocket: A simple, lightweight Java WebSocket server core for building real-time applications. Beginner-friendly, pure Java, and zero dependencies
License
AceAtDev/JSocket--java-simple-websocket
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
JSocket provides a simple yet powerful WebSocket implementation in Java with no external dependencies. Perfect for learning WebSocket internals, building custom real-time features, or integrating into existing Java applications.
Chess game demo built with JSocket
- Beginner-friendly code structure with extensive documentation
- RFC 6455 compliant WebSocket implementation
- Concurrent client handling with dedicated reader/writer threads
- Event-driven architecture via simple listener interface
- Working Chess game demo showcasing real-time capabilities
- Zero external dependencies - just pure Java
# Clone the repositorygit clone https://github.com/AceAtDev/JSocket--java-simple-websocketcd JSocket# Run the Chess server (using your IDE or command line)java javaWebsocketChess.chess.ChessServerMain# Open in browser: javaWebsocketChess/chess/clientApp/index.html# (Open in two tabs to play against yourself)
1️⃣Copy the core files fromjavaWebsocketChess/websocketCore/ into your project
2️⃣Create your handler:
publicclassMyWebSocketHandlerimplementsWebSocketListener {@OverridepublicvoidonOpen(ClientHandlerconnection) {connection.sendMessage("Welcome!"); }@OverridepublicvoidonMessage(ClientHandlerconnection,Stringmessage) {System.out.println("Received: " +message);connection.sendMessage("You said: " +message); }@OverridepublicvoidonClose(ClientHandlerconnection,intcode,Stringreason,booleanremote) {System.out.println("Connection closed: " +reason); }@OverridepublicvoidonError(ClientHandlerconnection,Exceptionex) {ex.printStackTrace(); }}
3️⃣Start the server:
publicstaticvoidmain(String[]args) {WebSocketServerserver =newWebSocketServer(8888,newMyWebSocketHandler());try {server.start();System.out.println("WebSocket server running on port 8888"); }catch (IOExceptione) {e.printStackTrace(); }}
JSocket's architecture is simple but powerful:
WebSocketServer: Manages TCP connections and handshakesClientHandler: Manages WebSocket connection lifecycleWebSocketDataReader/Writer: Handle frame reading/writingWebSocketFrame: Represents WebSocket protocol framesWebSocketListener: Interface for your application logic
- Learning WebSocket internals without complex dependencies
- Real-time chat applications
- Multiplayer games (like the included Chess demo)
- Live dashboards and monitoring tools
- Adding WebSocket capability to existing Java applications
For more detailed information:
- how it works - Detailed description of classes and methods
Contributions are welcome! Whether it's bug reports, feature requests, or code contributions:
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add some amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
JSocket isMIT licensed.
Special thanks to the amazingpython-websockets/websockets project for their wonderful documentation, which was invaluable in creating this repository.
About
JSocket: A simple, lightweight Java WebSocket server core for building real-time applications. Beginner-friendly, pure Java, and zero dependencies
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.

