Repolode
lxzan

lxzan/gws

A minimal, event-driven WebSocket server and client library for Go, with permessage-deflate and support for TCP, KCP and Unix sockets.

Stars
1,808
Forks
122
Open issues
0
Last commit
last month

What is it?

GWS (Go WebSocket) is a WebSocket library for Go built around a small event interface with OnOpen, OnMessage, OnClose, OnPing and OnPong callbacks. Each connection runs its own goroutine to drive its event loop, which keeps application code close to the business logic while protocol details stay hidden.

Beyond the basic API, it offers a Broadcaster that compresses a frame once for fan-out to many connections, context takeover for permessage-deflate with configurable window sizes, and a Dialer hook for connecting through SOCKS5 or HTTP proxies. It can also run over KCP and Unix domain sockets, and provides non-blocking asynchronous writes, file segment writes and a choice of ReadLoop, ReadMessage or NextReader for reading messages.

The project targets RFC 6455 and RFC 7692 compliance and reports passing the Autobahn test suite. It is intended for servers that hold many long-lived connections, such as gateways, chat, games and push services.

Key features

  • 01Event-driven API built on OnOpen, OnMessage, OnClose, OnPing and OnPong callbacks.
  • 02Broadcaster that compresses a message once for fan-out to many connections.
  • 03permessage-deflate with context takeover and configurable sliding window sizes.
  • 04Dialing through SOCKS5 or HTTP proxies via a custom Dialer.
  • 05Runs over TCP, KCP and Unix domain sockets.
  • 06Asynchronous non-blocking writes and segmented file writing.

Use cases

  • Building real-time chat or instant messaging backends in Go.
  • Running API gateways or hubs that keep many long-lived connections open.
  • Pushing live updates or pub/sub messages to browser or app clients.
  • Creating WebSocket clients that connect through a SOCKS5 proxy.

Quick start

  1. 1

    Install the library with Go

    go get -v github.com/lxzan/gws@latest
  2. 2

    Create a main.go with the Quick Start code and run the server on port 6666

Things to know

  • Requires Go 1.18 or newer.

Topics

FAQ

What is gws?
A minimal, event-driven WebSocket server and client library for Go, with permessage-deflate and support for TCP, KCP and Unix sockets. GWS (Go WebSocket) is a WebSocket library for Go built around a small event interface with OnOpen, OnMessage, OnClose, OnPing and OnPong callbacks. Each connection runs its own goroutine to drive its event loop, which keeps application code close to the business logic while protocol details stay hidden.
Is gws free to use? What license does it have?
gws is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
Is gws still maintained?
Updated within 6 months. The last commit to gws was on Sep 11, 2026.
What can I use gws for?
Building real-time chat or instant messaging backends in Go. Running API gateways or hubs that keep many long-lived connections open. Pushing live updates or pub/sub messages to browser or app clients. Creating WebSocket clients that connect through a SOCKS5 proxy.
How do I install gws?
Install the library with Go: go get -v github.com/lxzan/gws@latest Create a main.go with the Quick Start code and run the server on port 6666
Where can I get gws?
The source code and installation instructions are on GitHub: https://github.com/lxzan/gws

Summary generated by AI from the project's README. GitHub stats refresh daily.

Related projects