Documentation ¶
Overview ¶
Package websocket provides a wrapper for github.com/gorilla/websocket. The wrapper has limited features; the point is ease of use for some common cases. It does NOT check the request Origin header. All of its methods are safe for concurrent use. It automatically applies a send timeout. It transparently handles the closing handshake.
Index ¶
Constants ¶
const ( // SendTimeout is the amount of time to wait on a Send before giving up. SendTimeout = 5 * time.Second // CloseRecvTimeout is the amount of time waiting during Close // for the remote peer to send a Close message // before shutting down the connection. CloseRecvTimeout = 5 * time.Second // HandshakeTimeout is the amount of time to wait // for the connection handshake to complete. HandshakeTimeout = 5 * time.Second )
Variables ¶
var ErrCloseSent = websocket.ErrCloseSent
ErrCloseSent is returned by Send if sending to a connection that is closing.
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
A Conn is a websocket connection.
func Dial ¶
Dial dials a websocket and returns a new Conn.
If the handshake fails, a HandshakeError is returned.
func (*Conn) Close ¶
Close closes the websocket connection, unblocking any blocked calls to Recv or Send, and blocks until the closing handshake completes or CloseRecvTimeout timeout expires.
Close should not be called more than once.
func (*Conn) Recv ¶
Recv receives the next JSON-encoded message into msg. If msg is nill, the received message is discarded.
This function must be called continually until Close() is called, otherwise the connection will not respond to ping/pong messages.
Calling Recv on a closed connection returns io.EOF.
type HandshakeError ¶
type HandshakeError struct { // Status is the string representation of the HTTP response status code. Status string // StatusCode is the numeric HTTP response status code. StatusCode int }
A HandshakeError is returned if Dial fails the handshake.
func (HandshakeError) Error ¶
func (err HandshakeError) Error() string