ws

package
v0.0.0-...-79486b3 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2026 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ControlConn

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

ControlConn 控制 WebSocket 连接池,支持同一 taskID 多个并发连接

func NewControlConn

func NewControlConn() *ControlConn

NewControlConn 创建控制连接池

func (*ControlConn) Add

func (cc *ControlConn) Add(id string, conn *WebsocketManager)

Add 添加连接

func (*ControlConn) Get

func (cc *ControlConn) Get(id string) ([]*WebsocketManager, bool)

Get 获取指定 taskID 的所有连接

func (*ControlConn) Has

func (cc *ControlConn) Has(id string) bool

Has 检查指定 taskID 是否还有活跃的 control 连接

func (*ControlConn) Remove

func (cc *ControlConn) Remove(id string, conn *WebsocketManager)

Remove 移除特定连接

type TaskConn

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

TaskConn 任务 WebSocket 连接池

func NewTaskConn

func NewTaskConn() *TaskConn

NewTaskConn 创建任务连接池

func (*TaskConn) Add

func (tc *TaskConn) Add(id string, conn *WebsocketManager)

Add 添加连接

func (*TaskConn) Get

func (tc *TaskConn) Get(id string) (*WebsocketManager, bool)

Get 获取连接

func (*TaskConn) Remove

func (tc *TaskConn) Remove(id string)

Remove 移除连接

type WebsocketManager

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

WebsocketManager 管理 coder/websocket 连接,提供并发安全的写入

func Accept

Accept 从 HTTP 请求升级到 WebSocket 连接

func (*WebsocketManager) Close

func (w *WebsocketManager) Close() error

Close 关闭 WebSocket 连接

func (*WebsocketManager) Conn

func (w *WebsocketManager) Conn() *websocket.Conn

Conn 返回底层连接

func (*WebsocketManager) IP

func (w *WebsocketManager) IP() string

IP 返回客户端 IP

func (*WebsocketManager) ReadMessage

func (w *WebsocketManager) ReadMessage() ([]byte, error)

ReadMessage 读取消息,返回消息内容

func (*WebsocketManager) RemoteAddr

func (w *WebsocketManager) RemoteAddr() string

RemoteAddr 返回底层连接的远程地址

func (*WebsocketManager) SetRealIP

func (w *WebsocketManager) SetRealIP(ip string)

SetRealIP 设置客户端真实 IP(由浏览器上报)

func (*WebsocketManager) WriteJSON

func (w *WebsocketManager) WriteJSON(v any) error

WriteJSON 发送 JSON 消息

Jump to

Keyboard shortcuts

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