|
5 | 5 | <img src="assets/logo.png" alt="logo" width="300px"> |
6 | 6 | </div> |
7 | 7 |
|
8 | | -<h3 align="center">Simple, Fast, Reliable WebSocket Server & Client</h3> |
| 8 | +<h3 align="center">Simple · High Performance · Reliable WebSocket Server & Client Library</h3> |
9 | 9 |
|
10 | 10 | <div align="center"> |
11 | 11 |
|
|
21 | 21 |
|
22 | 22 | ### Introduction |
23 | 23 |
|
24 | | -GWS (Go WebSocket) is a very simple, fast, reliable and feature-rich WebSocket implementation written in Go. It is |
25 | | -designed to be used in highly-concurrent environments, and it is suitable for |
26 | | -building `API`, `Proxy`, `Game`, `Live Video`, `Message`, etc. It supports both server and client side with a simple API |
27 | | -which mean you can easily write a server or client by yourself. |
| 24 | +GWS (Go WebSocket) is a **simple, high‑performance and feature‑complete** WebSocket library written in Go. |
| 25 | +It is designed for **high‑concurrency** scenarios and is ideal for building **API gateways, long‑lived connection hubs, reverse proxies, IM / chat, online games, real‑time streaming, and push / subscribe systems**. |
| 26 | +GWS exposes an extremely **minimal, event‑driven API**, so you can build a stable WebSocket server or client with very little code. |
28 | 27 |
|
29 | | -GWS developed base on Event-Driven model. every connection has a goroutine to handle the event, and the event is able |
30 | | -to be processed in a non-blocking way. |
| 28 | +GWS is built on an event‑driven model: every connection has its own goroutine to drive the event loop, and events can be processed in a non‑blocking way. |
31 | 29 |
|
32 | 30 | ### Why GWS |
33 | 31 |
|
34 | | -- <font size=3>Simplicity and Ease of Use</font> |
| 32 | +- <font size=3>Simplicity & Developer Experience</font> |
35 | 33 |
|
36 | | - - **User-Friendly**: Simple and clear `WebSocket` Event API design makes server-client interaction easy. |
37 | | - - **Code Efficiency**: Minimizes the amount of code needed to implement complex WebSocket solutions. |
| 34 | + - **Event‑driven & intuitive**: The `Event` interface (`OnOpen / OnMessage / OnClose / OnPing / OnPong`) mirrors how you think about WebSocket lifecycles. |
| 35 | + - **High coding efficiency**: Protocol details are hidden behind a small, clear API, so you can focus almost entirely on business logic. |
38 | 36 |
|
39 | | -- <font size=3>High-Performance</font> |
| 37 | +- <font size=3>High Performance</font> |
40 | 38 |
|
41 | | - - **High IOPS Low Latency**: Designed for rapid data transmission and reception, ideal for time-sensitive |
42 | | - applications. |
43 | | - - **Low Memory Usage**: Highly optimized memory multiplexing system to minimize memory usage and reduce your cost of |
44 | | - ownership. |
| 39 | + - **High throughput & low latency**: Carefully tuned for WebSocket workloads such as echo servers and long‑lived push streams, making it a great fit for latency‑sensitive applications. |
| 40 | + - **Low memory footprint**: Aggressive buffer reuse and compression strategies significantly reduce memory and CPU cost under heavy concurrency. |
45 | 41 |
|
46 | | -- <font size=3>Reliability and Stability</font> |
47 | | - - **Robust Error Handling**: Advanced mechanisms to manage and mitigate errors, ensuring continuous operation. |
48 | | - - **Well-Developed Test Cases**: Passed all `Autobahn` test cases, fully compliant with `RFC 7692`. Unit test |
49 | | - coverage is almost 100%, covering all conditional branches. |
| 42 | +- <font size=3>Reliability & Standards Compliance</font> |
| 43 | + |
| 44 | + - **Robust error handling**: Clear, well‑defined behaviors for connection errors, protocol violations, compression failures, etc. |
| 45 | + - **Battle‑tested**: Passes all `Autobahn` test cases and is compliant with `RFC 6455` / `RFC 7692`. Unit tests cover almost all conditional branches. |
50 | 46 |
|
51 | 47 | ### Benchmark |
52 | 48 |
|
@@ -100,19 +96,20 @@ ok github.com/lxzan/gws 17.231s |
100 | 96 |
|
101 | 97 | ### Feature |
102 | 98 |
|
103 | | -- [x] Event API |
104 | | -- [x] Broadcast |
105 | | -- [x] Dial via Proxy |
106 | | -- [x] Context-Takeover |
107 | | -- [x] Concurrent & Asynchronous Non-Blocking Write |
108 | | -- [x] Segmented Writing of Large Files |
109 | | -- [x] Passed Autobahn Test Cases [Server](https://lxzan.github.io/gws/reports/servers/) / [Client](https://lxzan.github.io/gws/reports/clients/) |
| 99 | +- [x] **Event‑driven API** based on the `Event` interface, similar to common WebSocket SDKs. |
| 100 | +- [x] **Broadcast support** via `Broadcaster`, which reuses compressed frames for efficient fan‑out. |
| 101 | +- [x] **Dial via proxy** using a customizable `Dialer` (e.g. SOCKS5 / HTTP proxy). |
| 102 | +- [x] **Context‑takeover (permessage‑deflate)** with configurable sliding window sizes. |
| 103 | +- [x] **Segmented writing of large files** with `WriteFile` to reduce peak memory during large transfers. |
| 104 | +- [x] **Concurrent & asynchronous non‑blocking write** with built‑in task queues and `Writev` / `WritevAsync`. |
| 105 | +- [x] **Strong standards compatibility**, passing all Autobahn test cases |
| 106 | + [Server report](https://lxzan.github.io/gws/reports/servers/) / [Client report](https://lxzan.github.io/gws/reports/clients/) |
110 | 107 |
|
111 | 108 | ### Attention |
112 | 109 |
|
113 | | -- The errors returned by the gws.Conn export methods are ignorable, and are handled internally. |
114 | | -- Transferring large files with gws tends to block the connection. |
115 | | -- If HTTP Server is reused, it is recommended to enable goroutine, as blocking will prevent the context from being GC. |
| 110 | +- For most business use‑cases, errors returned by exported methods on `gws.Conn` can be treated as **informational**: the library has already taken appropriate action internally (e.g. closing the connection, emitting events). |
| 111 | +- When transferring **very large files**, a single connection may occupy bandwidth and I/O for a long time; you may want throttling, sharding or other flow‑control at the business layer. |
| 112 | +- If you reuse `net/http` (e.g. call `Upgrade` inside an HTTP handler), always call `ReadLoop` inside a **separate goroutine**, otherwise blocking will prevent the request context from being garbage‑collected in time. |
116 | 113 |
|
117 | 114 | ### Install |
118 | 115 |
|
|
0 commit comments