Documentation ¶
Index ¶
- Constants
- Variables
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) Flush() error
- func (c *Conn) Peek(n int) ([]byte, error)
- func (c *Conn) ReadMessage() (payload []byte, err error)
- func (c *Conn) WriteHeader(opcode int, length int) error
- func (c *Conn) WriteMessage(msgType int, msg []byte) (err error)
- func (c *Conn) WritePayload(b []byte) (err error)
- type Request
Constants ¶
const ( // TextMessage denotes a text data message. The text message payload is // interpreted as UTF-8 encoded text data. TextMessage = 1 // BinaryMessage denotes a binary data message. BinaryMessage = 2 // CloseMessage denotes a close control message. The optional message // payload contains a numeric code and text. Use the FormatCloseMessage // function to format a close message payload. CloseMessage = 8 // PingMessage denotes a ping control message. The optional message payload // is UTF-8 encoded text. PingMessage = 9 // PongMessage denotes a ping control message. The optional message payload // is UTF-8 encoded text. PongMessage = 10 )
The message types are defined in RFC 6455, section 11.8. https://datatracker.ietf.org/doc/html/rfc6455#section-11.8 https://datatracker.ietf.org/doc/html/rfc6455#section-5.5 note: 1) 3-7 are reserved for further non-control frames. 2) 11-16 are reserved for further control frames.
Variables ¶
var ( ErrMessageClose = errors.New("got client's close message") ErrMessageMaxRead = errors.New("continuation frame max read") )
var ( // ErrBadRequestMethod bad request method ErrBadRequestMethod = errors.New("bad method") // ErrNotWebSocket not websocket protocol ErrNotWebSocket = errors.New("not websocket protocol") // ErrBadWebSocketVersion bad websocket version ErrBadWebSocketVersion = errors.New("missing or bad WebSocket Version") // ErrChallengeResponse mismatch challenge response ErrChallengeResponse = errors.New("mismatch challenge/response") )
Functions ¶
This section is empty.
Types ¶
type Conn ¶
type Conn struct {
// contains filtered or unexported fields
}
Conn represents a WebSocket connection.
func Upgrade ¶
func Upgrade(closer io.ReadWriteCloser, rr *bufio.Reader, wr *bufio.Writer, req *Request) (conn *Conn, err error)
Upgrade Switching Protocols https://datatracker.ietf.org/doc/html/rfc6455#section-1.3
func (*Conn) ReadMessage ¶
ReadMessage 读取整个消息
func (*Conn) WriteHeader ¶
WriteHeader write header frame.
func (*Conn) WriteMessage ¶
WriteMessage write a message(跟read反着来就好) https://datatracker.ietf.org/doc/html/rfc6455#section-5.2 https://datatracker.ietf.org/doc/html/rfc6455#section-5.5 https://datatracker.ietf.org/doc/html/rfc6455#section-5.6
func (*Conn) WritePayload ¶
WritePayload write payload