# coder/websocket

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/coder-websocket).**

5,299 stars · 364 forks · Go · ISC

## Links

- GitHub: https://github.com/coder/websocket
- awesome-repositories: https://awesome-repositories.com/repository/coder-websocket.md

## Topics

`go` `http2` `idiomatic` `minimal` `websocket`

## Description

This is a minimal WebSocket library for Go designed for bidirectional real-time communication. It serves as a network protocol implementation for managing handshakes, frame masking, and control signals to enable the exchange of text and binary messages over persistent connections.

The library distinguishes itself by providing a connectivity layer that wraps browser WebSocket APIs for applications compiled to WebAssembly. It also functions as data compression middleware, utilizing deflate compression to reduce bandwidth usage for transmitted messages.

The project covers a broad range of networking capabilities, including connection lifecycle management via heartbeats and timeouts, protocol tunneling for wrapping arbitrary network protocols, and traffic management through message size limits and origin validation. It supports the transmission of structured data using formats such as JSON and Protobuf.

## Tags

### Networking & Communication

- [Go WebSocket Libraries](https://awesome-repositories.com/f/networking-communication/go-websocket-libraries.md) — A high-performance implementation of the WebSocket protocol written specifically for Go.
- [WebSocket Message Exchanges](https://awesome-repositories.com/f/networking-communication/text-and-binary-message-exchanges/websocket-message-exchanges.md) — Provides bidirectional transmission of text and binary frames over persistent WebSocket connections. ([source](https://github.com/coder/websocket/blob/master/conn.go))
- [Real-time Messaging](https://awesome-repositories.com/f/networking-communication/communication-platforms-services/communication-platforms/real-time-collaboration-suites/real-time-messaging.md) — Facilitates instant bidirectional communication between systems without the overhead of repeated request-response cycles. ([source](https://github.com/coder/websocket/blob/master/main_test.go))
- [Connection Establishment Protocols](https://awesome-repositories.com/f/networking-communication/communication-protocols-architectures/communication-protocols-standards/network-protocols/connection-establishment-protocols.md) — Initiates and upgrades bidirectional network connections between clients and servers. ([source](https://github.com/coder/websocket#readme))
- [WebSocket and Fallback Connection Establishment](https://awesome-repositories.com/f/networking-communication/communication-protocols-architectures/communication-protocols-standards/network-protocols/connection-establishment-protocols/websocket-and-fallback-connection-establishment.md) — Performs the initial handshake with a remote server to establish a persistent bidirectional connection. ([source](https://github.com/coder/websocket/blob/master/AGENTS.md))
- [Connection Control Frame Handlers](https://awesome-repositories.com/f/networking-communication/connection-control-frame-handlers.md) — Implements logic to handle protocol-level control messages like ping, pong, and close frames. ([source](https://github.com/coder/websocket/blob/master/AGENTS.md))
- [WebSocket Frame Processors](https://awesome-repositories.com/f/networking-communication/connection-control-frame-handlers/websocket-frame-processors.md) — Implements low-level processing for encoding and decoding WebSocket data and control frames using optimized buffers. ([source](https://github.com/coder/websocket/blob/master/frame_test.go))
- [WebSocket Ping/Pong Keepalives](https://awesome-repositories.com/f/networking-communication/connection-keepalives/websocket-ping-pong-keepalives.md) — Maintains connection health by exchanging WebSocket ping and pong frames. ([source](https://github.com/coder/websocket/blob/master/conn_test.go))
- [Websocket Connection Managers](https://awesome-repositories.com/f/networking-communication/connection-management/websocket-connection-managers.md) — Manages persistent WebSocket connections, including subprotocol negotiation and resource cleanup. ([source](https://github.com/coder/websocket/blob/master/conn_test.go))
- [Connection Termination](https://awesome-repositories.com/f/networking-communication/connection-management/websocket-connection-managers/connection-termination.md) — Implements graceful shutdown of connections using formal WebSocket status codes and handshakes. ([source](https://github.com/coder/websocket/blob/master/close.go))
- [Health Monitoring](https://awesome-repositories.com/f/networking-communication/connection-management/websocket-connection-managers/health-monitoring.md) — Monitors connection stability through the exchange of ping frames and pong responses. ([source](https://github.com/coder/websocket/blob/master/example_test.go))
- [Data Framing](https://awesome-repositories.com/f/networking-communication/data-framing.md) — Encapsulates data into binary frames with headers for length, masking, and control signals.
- [Frame Masking](https://awesome-repositories.com/f/networking-communication/frame-masking.md) — Applies a rotating masking key to data frames using bitwise XOR operations for secure transmission.
- [Network Protocol Implementations](https://awesome-repositories.com/f/networking-communication/network-protocol-implementations.md) — Implements the low-level WebSocket protocol, managing handshakes, frame masking, and control signals.
- [Connection Lifecycle Managers](https://awesome-repositories.com/f/networking-communication/network-reliability-diagnostics/connection-session-management/connection-management/connection-lifecycle-managers.md) — Handles automated state transitions, heartbeats, and closing connections with specific status codes. ([source](https://github.com/coder/websocket/blob/master/example_test.go))
- [Connection Hijacking](https://awesome-repositories.com/f/networking-communication/persistent-network-connections/connection-hijacking.md) — Extracts the underlying network connection from a response writer to switch to a bidirectional stream. ([source](https://github.com/coder/websocket/blob/master/hijack.go))
- [WebSocket Message Readers](https://awesome-repositories.com/f/networking-communication/websocket-message-readers.md) — Implements the ability to retrieve incoming messages as byte slices or streams while processing control frames. ([source](https://github.com/coder/websocket/blob/master/read.go))
- [WebSocket Message Writers](https://awesome-repositories.com/f/networking-communication/websocket-message-writers.md) — Provides the capability to write data as single atomic messages or streams to a WebSocket connection. ([source](https://github.com/coder/websocket/blob/master/write.go))
- [WebSocket Frame Compression](https://awesome-repositories.com/f/networking-communication/data-compression/message-body-compressors/websocket-frame-compression.md) — Compresses individual WebSocket frames using the deflate algorithm to reduce network bandwidth.
- [WebSocket Proxy Tunnels](https://awesome-repositories.com/f/networking-communication/distributed-systems-p2p/distributed-computing/communication-protocols/websocket-implementations/websocket-servers/websocket-proxy-tunnels.md) — Provides the ability to tunnel network traffic across restricted boundaries using WebSocket connections.
- [JSON Message Exchanges](https://awesome-repositories.com/f/networking-communication/message-passing/json-message-exchanges.md) — Exchanges structured JSON messages over a persistent connection to synchronize state. ([source](https://github.com/coder/websocket/blob/master/example_test.go))
- [Tunneling Protocols](https://awesome-repositories.com/f/networking-communication/network-infrastructure-routing/network-proxying-tools/network-proxies/tunneling-protocols.md) — Provides the ability to encapsulate arbitrary network protocols within a WebSocket connection to bypass restrictive environments. ([source](https://github.com/coder/websocket/blob/master/netconn.go))
- [Browser API Wrappers](https://awesome-repositories.com/f/networking-communication/tcp-connection-lifecycles/tcp-client-connections/webassembly-tcp-connections/browser-api-wrappers.md) — Provides a connectivity layer that wraps browser WebSocket APIs for applications compiled to WebAssembly. ([source](https://github.com/coder/websocket/blob/master/doc.go))
- [WebSocket API Wrappers](https://awesome-repositories.com/f/networking-communication/tcp-connection-lifecycles/tcp-client-connections/webassembly-tcp-connections/websocket-api-wrappers.md) — Provides a connectivity layer that wraps browser WebSocket APIs for Go applications compiled to WebAssembly.
- [WebSocket Payload Compressions](https://awesome-repositories.com/f/networking-communication/tunnel-payload-compression/websocket-payload-compressions.md) — Lowers data transfer volume by applying compression to all outgoing and incoming frames. ([source](https://github.com/coder/websocket/blob/master/AGENTS.md))

### Data & Databases

- [Real-Time Data Streaming](https://awesome-repositories.com/f/data-databases/real-time-data-streaming.md) — Enables real-time delivery and processing of data streams from remote peers over persistent connections. ([source](https://github.com/coder/websocket/blob/master/main_test.go))
- [JSON Data Exchange](https://awesome-repositories.com/f/data-databases/json-data-exchange.md) — Uses JSON for transporting structured state and configuration between clients and servers. ([source](https://github.com/coder/websocket#readme))
- [Structured Message Serialization](https://awesome-repositories.com/f/data-databases/structured-message-serialization.md) — Supports serializing and deserializing data using JSON and Protobuf formats for network transmission. ([source](https://github.com/coder/websocket/blob/master/doc.go))

### Security & Cryptography

- [WebSocket Frame Masking](https://awesome-repositories.com/f/security-cryptography/data-masking-tools/websocket-frame-masking.md) — Provides the required masking-key XOR transformation for secure WebSocket data transmission. ([source](https://github.com/coder/websocket/blob/master/mask_amd64.s))
- [Request Size Limiters](https://awesome-repositories.com/f/security-cryptography/request-size-limiters.md) — Protects server resources from memory exhaustion by rejecting incoming frames that exceed defined byte limits. ([source](https://github.com/coder/websocket/blob/master/conn_test.go))
- [Response Size Limits](https://awesome-repositories.com/f/security-cryptography/request-size-limiters/output-size-constraints/response-size-limits.md) — Caps the maximum number of bytes allowed for a single incoming message to prevent memory exhaustion. ([source](https://github.com/coder/websocket/blob/master/read.go))

### Software Engineering & Architecture

- [Network Connection Lifecycles](https://awesome-repositories.com/f/software-engineering-architecture/resource-lifecycle-management/context-managers/network-connection-lifecycles.md) — Uses Go contexts and heartbeats to manage connection timeouts and prevent resource leaks.

### Web Development

- [Protocol Upgrades](https://awesome-repositories.com/f/web-development/protocol-upgrades.md) — Provides mechanisms to upgrade standard HTTP connections to a persistent bidirectional WebSocket stream.
- [Real-Time Communication](https://awesome-repositories.com/f/web-development/real-time-communication.md) — Provides persistent, bidirectional data streaming for sending and receiving text and binary messages.
- [Real-Time Communication Protocols](https://awesome-repositories.com/f/web-development/real-time-communication-protocols.md) — Enables bidirectional, low-latency data exchange between clients and servers using the WebSocket protocol.
- [Browser API Wrappers](https://awesome-repositories.com/f/web-development/api-bridges/browser-api-wrappers.md) — Wraps the native browser WebSocket API to provide a consistent interface for WebAssembly applications.
