websocket

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleWebSocket

func HandleWebSocket(hub *Hub) router.HandlerFunc

HandleWebSocket 处理 WebSocket 连接

Types

type Client

type Client struct {
	ID   string
	Conn *websocket.Conn
	Send chan []byte
	Hub  *Hub
}

Client WebSocket 客户端

func (*Client) ReadPump

func (c *Client) ReadPump()

ReadPump 读取客户端消息

func (*Client) WritePump

func (c *Client) WritePump()

WritePump 写入消息到客户端

type Hub

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

Hub WebSocket 集线器

func NewHub

func NewHub() *Hub

NewHub 创建集线器

func (*Hub) Broadcast

func (h *Hub) Broadcast(message []byte)

Broadcast 广播消息

func (*Hub) ClientCount

func (h *Hub) ClientCount() int

ClientCount 获取客户端数量

func (*Hub) GetClients

func (h *Hub) GetClients() []*Client

GetClients 获取所有客户端

func (*Hub) Run

func (h *Hub) Run()

Run 运行集线器

func (*Hub) SendToClient

func (h *Hub) SendToClient(clientID string, message []byte)

SendToClient 发送消息给指定客户端

Jump to

Keyboard shortcuts

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