Documentation
¶
Overview ¶
Application data: y bytes
Arbitrary "Application data", taking up the remainder of the frame after any "Extension data". The length of the "Application data" is equal to the payload length minus the length of the "Extension data".
Package websocket .
Index ¶
- Constants
- Variables
- func SetDebug(debug bool)
- type CloseError
- type Conn
- func (c *Conn) Close()
- func (c *Conn) Connected() bool
- func (c *Conn) Ping() (err error)
- func (c *Conn) ReadMessage() (mt MessageType, msg []byte, err error)
- func (c *Conn) SendBinary(r io.Reader) (err error)
- func (c *Conn) SendMessage(text string) (err error)
- func (c *Conn) SetPongHandler(handler func(s string))
- type ConnState
- type DialOption
- type Frame
- type HandshakeError
- type MessageType
- type OpCode
- type Upgrader
Constants ¶
const ( // NoFrame . NoFrame MessageType = 0 // TextMessage . TextMessage = MessageType(opCodeText) // BinaryMessage . BinaryMessage = MessageType(opCodeBinary) // CloseMessage . CloseMessage = MessageType(opCodeClose) // PingMessage . PingMessage = MessageType(opCodePing) // PongMessage . PongMessage = MessageType(opCodePong) )
const ( CloseNormalClosure = 1000 CloseGoingAway = 1001 CloseProtocolError = 1002 CloseUnsupportedData = 1003 CloseNoStatusReceived = 1005 CloseAbnormalClosure = 1006 CloseInvalidFramePayloadData = 1007 ClosePolicyViolation = 1008 CloseMessageTooBig = 1009 CloseMandatoryExtension = 1010 CloseInternalServerErr = 1011 CloseServiceRestart = 1012 CloseTryAgainLater = 1013 CloseTLSHandshake = 1015 )
Variables ¶
var ( ErrMaskNotSet = errors.New("mask is not set") ErrMaskSet = errors.New("mask is set") )
var ( // ErrUnexpectedEOF . ErrUnexpectedEOF = &CloseError{Code: CloseAbnormalClosure, Text: io.ErrUnexpectedEOF.Error()} // ErrInvalidFrame . ErrInvalidFrame = &CloseError{Code: CloseProtocolError, Text: "invalid frame: "} )
var ( // ErrInvalidData . ErrInvalidData = errors.New("invalid websocket data frame") )
var ( // ErrInvalidSchema . ErrInvalidSchema = errors.New("invalid schema") )
Functions ¶
Types ¶
type Conn ¶
type Conn struct {
// State marks Conn current state, and it is basis of controlling the Conn.
// unnecessary: maybe import an state machine to manage with
State ConnState
// contains filtered or unexported fields
}
Conn .
func (*Conn) ReadMessage ¶
func (c *Conn) ReadMessage() (mt MessageType, msg []byte, err error)
ReadMessage . it will block to read message
func (*Conn) SendBinary ¶
SendBinary . sending bianry data to other-side
func (*Conn) SendMessage ¶
SendMessage . sending text data to other side
func (*Conn) SetPongHandler ¶ added in v1.1.0
SetPongHandler handler would be called while the Conn
type DialOption ¶
type DialOption func(o *options)
func WithTLS ¶
func WithTLS(cfg *tls.Config) DialOption
WithTLS generate DialOption with tls.Config.
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
&tls.Config{
Certificates: []tls.Certificate{cert},
}
type Frame ¶
type Frame struct {
Fin uint16 // 1 bit
RSV1 uint16 // 1 bit, 0
RSV2 uint16 // 1 bit, 0
RSV3 uint16 // 1 bit, 0
OpCode OpCode // 4 bits
Mask uint16 // 1 bit
// Payload length: 7 bits, 7+16 bits, or 7+64 bits
//
// if PayloadLen = 0 - 125, actual_payload_length = PayloadLen
// if PayloadLen = 126, actual_payload_length = PayloadExtendLen[:16]
// if PayloadLen = 127, actual_payload_length = PayloadExtendLen[:]
PayloadLen uint16 // 7 bits
PayloadExtendLen uint64 // 64 bits
MaskingKey uint32 // 32 bits
Payload []byte // no limit by RFC6455
}
Frame create an struct to contains WebSocket base frame data, and help to assemble and read data over TCP bytes stream
NOTICE: this definition wastes more space to help understand and each field should be unexported
!!!!CURRENTLY, THIS FRAME NOT CONSIDER ABOUT FRAGMENT!!!!
type HandshakeError ¶
type HandshakeError struct {
Text string
}
HandshakeError .
func (HandshakeError) Error ¶
func (e HandshakeError) Error() string
type Upgrader ¶
Upgrader std.HTTP / fasthttp / gin etc
func (Upgrader) Upgrade ¶
Upgrade handle websocket upgrade request
NOTICE: why returnError and hackHandshakeResponse both exists: https://stackoverflow.com/questions/32657603/why-do-i-get-the-error-message-http-response-write-on-hijacked-connection
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
fragment
command
|
|
|
transferring-binary
command
|
|
|
use-as-client
command
|
|
|
use-as-server
command
|
|
|
with-tls
command
|