Documentation
¶
Index ¶
- type ControlConn
- type TaskConn
- type WebsocketManager
- func (w *WebsocketManager) Close() error
- func (w *WebsocketManager) Conn() *websocket.Conn
- func (w *WebsocketManager) IP() string
- func (w *WebsocketManager) ReadMessage() ([]byte, error)
- func (w *WebsocketManager) RemoteAddr() string
- func (w *WebsocketManager) SetRealIP(ip string)
- func (w *WebsocketManager) WriteJSON(v any) error
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 (*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 连接池
type WebsocketManager ¶
type WebsocketManager struct {
// contains filtered or unexported fields
}
WebsocketManager 管理 coder/websocket 连接,提供并发安全的写入
func Accept ¶
func Accept(w http.ResponseWriter, r *http.Request) (*WebsocketManager, error)
Accept 从 HTTP 请求升级到 WebSocket 连接
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 消息
Click to show internal directories.
Click to hide internal directories.