Documentation
¶
Overview ¶
websocket provides an implementation of the WebSocket protocol in go.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrRequestNotWebsocket indicates that the HTTP request provided does not specify // instructions for a WebSocket upgrade. ErrRequestNotWebsocket = errors.New("the request does not specify a websocket upgrade") // ErrVersionNotSupported indicates that the version provided in the request is not // supported. Currently supported versions: 13 (as per the RFC). ErrVersionNotSupported = errors.New("the request specifies an unsupported version") // ErrKeyNotProvided indicates that there is no Sec-WebSocket-Key passed in by the // client. ErrKeyNotProvided = errors.New("the request does not specify a Sec-WebSocket-Key") // ErrHijackFailed indicates an error with hijacking the underlying connection from // http.ResponseWriter. ErrHijackFailed = errors.New("unable to hijack the http connection") // ErrConnectionRead indicates an error reading from the underlying connection. ErrConnectionRead = errors.New("reading from the underlying connection failed") // ErrConnectionWrite indicates an error writing to the underlying connection. ErrConnectionWrite = errors.New("writing to the underlying connection failed") // ErrConnectionClosed indicates that the underlying connection is closed. This connection // cannot be read from or written to. ErrConnectionClosed = errors.New("connection is closed") // ErrMalformedFrame indicates that the server recieved an unexpectedly formed frame. ErrMalformedFrame = errors.New("websocket frame is malformed") )
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn represents a WebSocket connection. All public methods on Conn are safe to be simultaneously called.
func AcceptHTTP ¶
AcceptHTTP handles a WebSocket HTTP request from the net/http client. It may return an error if the HTTP request is not a WebSocket connection, the WebSocket version is not supported, the Sec-WebSocket-Key is not provided, or hijacking the underlying connection fails.
func From ¶
func From(c io.ReadWriteCloser) *Conn
From returns a new WebSocket Conn from a value with a type that implements the io.ReadWriteCloser interface, notably net.Conn. It is expected that this connection will not be read from, written to, or closed once passed into this function.
func (*Conn) Close ¶
Close marks the connection as closed and closes the underlying connection. It may return an error if there is an issue closing the underlying connection.
func (*Conn) Ping ¶
Ping writes a ping frame to the connection. If a nil context is specified, it will default to five seconds. If no response is reached within the duration, it will return false. It may return an error if there is an issue writing to the connection.
If there is a ping that has not recieved a pong yet, calling this function will NOT write another ping frame, but will block until it recieves a pong.
type Message ¶
type Message struct {
Type MessageType
Data []byte
}
Message represents a WebSocket message.
type MessageType ¶
type MessageType uint8
MessageType represents the possible types of messages.
const ( // MessageText is a UTF-8 encoded string. MessageText MessageType = 0 // MessageBinary represents binary data. MessageBinary MessageType = 1 // MessageClose represents a close handshake. MessageClose MessageType = 2 // MessagePing represents a ping message from // the client. MessagePing MessageType = 3 // MessagePong represents a pong message (usually // in return to a ping message). MessagePong MessageType = 4 )
func (MessageType) String ¶
func (t MessageType) String() string
String returns the MessageType as a string.