Documentation ¶
Index ¶
- Variables
- type ConnectionState
- type RecConn
- func (rc *RecConn) Close()
- func (rc *RecConn) Dial(urlStr string, reqHeader http.Header)
- func (rc *RecConn) GetConnectionState() ConnectionState
- func (rc *RecConn) GetDialError() error
- func (rc *RecConn) GetHTTPResponse() *http.Response
- func (rc *RecConn) ReadJSON(v interface{}) error
- func (rc *RecConn) ReadMessage() (messageType int, message []byte, err error)
- func (rc *RecConn) Restart()
- func (rc *RecConn) Shutdown(writeWait time.Duration)
- func (rc *RecConn) Wait()
- func (rc *RecConn) WriteJSON(v interface{}) error
- func (rc *RecConn) WriteMessage(messageType int, data []byte) error
Constants ¶
This section is empty.
Variables ¶
var ErrNotConnected = errors.New("websocket: not connected")
ErrNotConnected is returned when the application read/writes a message and the connection is closed
Functions ¶
This section is empty.
Types ¶
type ConnectionState ¶
type ConnectionState int
const ( Disconnected ConnectionState = iota Connected )
type RecConn ¶
type RecConn struct { // RecIntervalMin specifies the initial reconnecting interval, // default to 2 seconds RecIntervalMin time.Duration // RecIntervalMax specifies the maximum reconnecting interval, // default to 30 seconds RecIntervalMax time.Duration // RecIntervalFactor specifies the rate of increase of the reconnection // interval, default to 1.5 RecIntervalFactor float64 // HandshakeTimeout specifies the duration for the handshake to complete, // default to 2 seconds HandshakeTimeout time.Duration // SubscribeHandler fires after the connection successfully establish. SubscribeHandler func() error // KeepAliveTimeout is an interval for sending ping/pong messages // disabled if 0 KeepAliveTimeout time.Duration *websocket.Conn sync.RWMutex // contains filtered or unexported fields }
func (*RecConn) Close ¶
func (rc *RecConn) Close()
Close closes the underlying network connection without sending or waiting for a close frame.
func (*RecConn) Dial ¶
Dial creates a new client connection. The URL specifies the host and request URI. Use requestHeader to specify the origin (Origin), sub protocols (Sec-WebSocket-Protocol) and cookies (Cookie). Use GetHTTPResponse() method for the response.Header to get the selected sub protocol (Sec-WebSocket-Protocol) and cookies (Set-Cookie).
func (*RecConn) GetConnectionState ¶
func (rc *RecConn) GetConnectionState() ConnectionState
GetConnectionState returns the WebSocket connection state
func (*RecConn) GetDialError ¶
GetDialError returns the last dialer error. nil on successful connection.
func (*RecConn) GetHTTPResponse ¶
GetHTTPResponse returns the http response from the handshake. Useful when WebSocket handshake fails, so that callers can handle redirects, authentication, etc.
func (*RecConn) ReadJSON ¶
ReadJSON reads the next JSON-encoded message from the connection and stores it in the value pointed to by v.
See the documentation for the encoding/json Unmarshal function for details about the conversion of JSON to a Go value.
If the connection is closed ErrNotConnected is returned
func (*RecConn) ReadMessage ¶
ReadMessage is a helper method for getting a reader using NextReader and reading from that reader to a buffer.
If the connection is closed ErrNotConnected is returned
func (*RecConn) Restart ¶
func (rc *RecConn) Restart()
Restart will try to close connection and reconnect.
func (*RecConn) Shutdown ¶
Shutdown gracefully closes the connection by sending the websocket.CloseMessage. The writeWait param defines the duration before the deadline of the write operation is hit.
func (*RecConn) Wait ¶
func (rc *RecConn) Wait()
Wait will block until the connection is established.