Documentation ¶
Overview ¶
Package websocket is a lightweight client implementation of the WebSocket protocol (RFC 6455). It is designed specifically for fast, efficient and idiomatic client-side communication with Chrome DevTools in Blink-based browsers.
Examples for unsupported features: server-side functionality, proxies, TLS for "wss://" addresses, and handshake customizations such as sub-protocols, extensions, and other HTTP headers (e.g. authentication, cookies).
Specifically, this implementation does not support the "permessage-deflate" extension (RFC 7692), for the same reasons it doesn't support TLS: almost all communication with Chrome DevTools should happen on the same localhost, and most transactions involve very small amounts of data, so the security benefits of TLS and performance benefits of compression become irrelevant in this use-case, and are in fact wasteful and unnecessarily slow.
More readaing materials about other WebSocket implementations:
• https://centrifugal.github.io/centrifugo/blog/scaling_websocket/
• https://www.freecodecamp.org/news/million-websockets-and-go-cc58418460bb/
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn defines a WebSocket connection with a buffered I/O interface.
func Handshake ¶
Handshake initiates a WebSocket connection with "ws://addr/path", based on https://datatracker.ietf.org/doc/html/rfc6455#section-4.1.
func NewConn ¶
NewConn initializes a WebSocket connection based on an open TCP connection. This does not initiate a WebSocket handshake, nor do you need to call it directly. Instead, call the `Handshake` function.
func (*Conn) Close ¶
Close sends a "connection close" control frame to a WebSocket server, and then closes the underlying TCP network connection. Valid status codes are described in https://datatracker.ietf.org/doc/html/rfc6455#section-7.4.1, and the reason is a UTF-8-encoded string which may be empty. Based on https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.1 and https://datatracker.ietf.org/doc/html/rfc6455#section-7.
func (*Conn) Read ¶
Read receives a full message from a WebSocket server. It handles all the implementation details internally, such as frame de/fragmentation, masking, and handling control frames.
func (*Conn) WriteBinary ¶
WriteBinary sends a full binary text message to a WebSocket server. It handles all the implementation details internally, such as frame de/fragmentation, masking, and handling control frames.
func (*Conn) WritePing ¶
WritePing sends a "ping" control frame to a WebSocket server, as a keep-alive or as a means to verify that the server is still responsive. Based on https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.2.
func (*Conn) WritePong ¶
WritePong sends a "pong" control frame to a WebSocket server, as a response to a "ping" (with the ping's "application data" payload), or as an unsolicited unidirectional heartbeat. Based on https://datatracker.ietf.org/doc/html/rfc6455#section-5.5.3.