Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 4fb4b3a

Browse files
Create README.md
1 parent 18c684e commit 4fb4b3a

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

‎README.md‎

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# JSocket 🚀
2+
3+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4+
[![Java](https://img.shields.io/badge/Java-8+-blue.svg)](https://www.java.com)
5+
6+
#### A lightweight, easy-to-understand Java WebSocket server for real-time applications
7+
8+
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.
9+
10+
![Chess Game Demo](docs/images/chess-demo.gif)
11+
12+
*Chess game demo built with JSocket*
13+
14+
## ✨ Features
15+
16+
- **Beginner-friendly** code structure with extensive documentation
17+
- **RFC 6455 compliant** WebSocket implementation
18+
- **Concurrent client handling** with dedicated reader/writer threads
19+
- **Event-driven architecture** via simple listener interface
20+
- **Working Chess game demo** showcasing real-time capabilities
21+
- **Zero external dependencies** - just pure Java
22+
23+
## 🚀 Quick Start
24+
25+
### Run the Chess Demo
26+
27+
```bash
28+
# Clone the repository
29+
git clone https://github.com/your-username/JSocket.git
30+
cd JSocket
31+
32+
# Run the Chess server (using your IDE or command line)
33+
java javaWebsocketChess.chess.ChessServerMain
34+
35+
# Open in browser: javaWebsocketChess/chess/clientApp/index.html
36+
# (Open in two tabs to play against yourself)
37+
```
38+
39+
### Use JSocket in Your Project
40+
41+
1️⃣ **Copy the core files** from `javaWebsocketChess/websocketCore/` into your project
42+
43+
2️⃣ **Create your handler:**
44+
45+
```java
46+
public class MyWebSocketHandler implements WebSocketListener {
47+
@Override
48+
public void onOpen(ClientHandler connection) {
49+
connection.sendMessage("Welcome!");
50+
}
51+
52+
@Override
53+
public void onMessage(ClientHandler connection, String message) {
54+
System.out.println("Received: " + message);
55+
connection.sendMessage("You said: " + message);
56+
}
57+
58+
@Override
59+
public void onClose(ClientHandler connection, int code, String reason, boolean remote) {
60+
System.out.println("Connection closed: " + reason);
61+
}
62+
63+
@Override
64+
public void onError(ClientHandler connection, Exception ex) {
65+
ex.printStackTrace();
66+
}
67+
}
68+
```
69+
70+
3️⃣ **Start the server:**
71+
72+
```java
73+
public static void main(String[] args) {
74+
WebSocketServer server = new WebSocketServer(8888, new MyWebSocketHandler());
75+
try {
76+
server.start();
77+
System.out.println("WebSocket server running on port 8888");
78+
} catch (IOException e) {
79+
e.printStackTrace();
80+
}
81+
}
82+
```
83+
84+
## 🧩 Key Components
85+
86+
JSocket's architecture is simple but powerful:
87+
88+
- **`WebSocketServer`**: Manages TCP connections and handshakes
89+
- **`ClientHandler`**: Manages WebSocket connection lifecycle
90+
- **`WebSocketDataReader/Writer`**: Handle frame reading/writing
91+
- **`WebSocketFrame`**: Represents WebSocket protocol frames
92+
- **`WebSocketListener`**: Interface for your application logic
93+
94+
## 🔍 Use Cases
95+
96+
- **Learning WebSocket internals** without complex dependencies
97+
- **Real-time chat applications**
98+
- **Multiplayer games** (like the included Chess demo)
99+
- **Live dashboards and monitoring tools**
100+
- **Adding WebSocket capability** to existing Java applications
101+
102+
## 📚 Documentation
103+
104+
For more detailed information:
105+
106+
- **[how it works](docs/HowItWorks.md)** - Detailed description of classes and methods
107+
108+
## 🤝 Contributing
109+
110+
Contributions are welcome! Whether it's bug reports, feature requests, or code contributions:
111+
112+
- Fork the repository
113+
- Create your feature branch: `git checkout -b feature/amazing-feature`
114+
- Commit your changes: `git commit -m 'Add some amazing feature'`
115+
- Push to the branch: `git push origin feature/amazing-feature`
116+
- Open a Pull Request
117+
118+
## 📄 License
119+
120+
JSocket is [MIT licensed](LICENSE.md).
121+
122+
---
123+
124+
#### Developed with ❤️ for the craft of developing
125+
126+
[Report Bug](https://github.com/AceAtDev/JSocket--java-simple-websocket-/issues)
127+
[Request Feature](https://github.com/AceAtDev/JSocket--java-simple-websocket-/issues)
128+
129+
---
130+
131+
## 🙏 Acknowledgements
132+
133+
Special thanks to the amazing [python-websockets/websockets](https://github.com/python-websockets/websockets) project for their wonderful documentation, which was invaluable in creating this repository.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /