websocket

package
v1.12.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetDialer

func SetDialer(d *websocket.Dialer)

SetDialer 设置 websocket dialer

func SetUpgrader

func SetUpgrader(up *websocket.Upgrader)

SetUpgrader 设置 websocket Upgrader

Types

type DialConn

type DialConn struct {
	// contains filtered or unexported fields
}

DialConn websocket拨号连接,支持(读/写)失败重连

func Dial

func Dial(ctx context.Context, addr string, header http.Header) (*DialConn, error)

Dial 创建一个websocket拨号连接

func (*DialConn) Close

func (c *DialConn) Close() error

Close 关闭连接

func (*DialConn) Read

func (c *DialConn) Read(reconnectTimeout time.Duration, handler func(msg *Message)) error

Read 读消息,若失败会尝试重连 (reconnectTimeout<=0 表示重连不超时)

func (*DialConn) Write

func (c *DialConn) Write(reconnectTimeout time.Duration, msg *Message) error

Write 写消息,若失败会尝试重连 (reconnectTimeout<=0 表示重连不超时)

type Message

type Message struct {
	// contains filtered or unexported fields
}

Message websocket消息

func BinaryMessage

func BinaryMessage(b []byte) *Message

func CloseMessage

func CloseMessage(code int, text string) *Message

func NewMessage

func NewMessage(t int, b []byte) *Message

func PingMessage

func PingMessage(b []byte) *Message

func PongMessage

func PongMessage(b []byte) *Message

func TextMessage

func TextMessage(s string) *Message

func (*Message) T

func (m *Message) T() int

func (*Message) V

func (m *Message) V() []byte

type UpgradeConn

type UpgradeConn struct {
	// contains filtered or unexported fields
}

UpgradeConn websocket协议连接

func Upgrade

func Upgrade(w http.ResponseWriter, r *http.Request, authFn func(ctx context.Context, msg *Message) (*Message, error)) (*UpgradeConn, error)

Upgrade upgrades the HTTP server connection to the WebSocket protocol.

func (*UpgradeConn) Close

func (c *UpgradeConn) Close() error

Close 关闭连接

func (*UpgradeConn) Read

func (c *UpgradeConn) Read(ctx context.Context, handler func(ctx context.Context, msg *Message) (*Message, error)) error

Read 读消息

func (*UpgradeConn) Write

func (c *UpgradeConn) Write(ctx context.Context, msg *Message) error

Write 写消息

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL