websocket

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Context

type Context struct {
	Id       uint64
	Conn     net.Conn
	Request  *Request
	Response *Response
	Server   *Server
}

func (*Context) Gc

func (c *Context) Gc()

Gc 回收资源

func (*Context) Init

func (c *Context) Init(id uint64, conn net.Conn, server *Server)

Init 初始化

type Handler

type Handler struct {
	HandlerInterface
}

func (*Handler) Check

func (handler *Handler) Check(httpCtx *ntHttp.Context) (bool, string)

Check 检查:是否跨域,身份验证

func (*Handler) OnBinaryMessage

func (handler *Handler) OnBinaryMessage(wsCtx *Context, message string) error

OnBinaryMessage 2: 二进制消息

func (*Handler) OnClose

func (handler *Handler) OnClose(wsCtx *Context) error

OnClose close

func (*Handler) OnHttpError

func (handler *Handler) OnHttpError(httpCtx *ntHttp.Context, code int, message string)

OnHttpError 抿手阶段出错 HTTP 输出

func (*Handler) OnPing

func (handler *Handler) OnPing(wsCtx *Context) error

OnPing ping

func (*Handler) OnPong

func (handler *Handler) OnPong(wsCtx *Context) error

OnPong pong

func (*Handler) OnRequest

func (handler *Handler) OnRequest(httpCtx *ntHttp.Context) error

OnRequest 请求

func (*Handler) OnTextMessage

func (handler *Handler) OnTextMessage(wsCtx *Context, message string) error

OnTextMessage 1: 文本消息

func (*Handler) OnWebsocketError

func (handler *Handler) OnWebsocketError(wsCtx *Context, code int, message string)

OnWebsocketError 传数数据阶段出错

func (*Handler) Process

func (handler *Handler) Process(wsCtx *Context) error

Start 启动

type HandlerInterface

type HandlerInterface interface {

	// OnRequest 默认请求, 未升级到 websocket HTTP 请求
	OnRequest(*ntHttp.Context) error

	// Check 检查:是否跨域,身份验证
	Check(*ntHttp.Context) (bool, string)

	// OnHttpError 出错
	OnHttpError(*ntHttp.Context, int, string)

	// OnTextMessage 1: 文本消息
	OnTextMessage(*Context, string) error

	// OnBinaryMessage 2: 二进制消息
	OnBinaryMessage(*Context, string) error

	// OnClose close
	OnClose(*Context) error

	// OnPing ping
	OnPing(*Context) error

	// OnPong pong
	OnPong(*Context) error

	// OnWebsocketError 出错
	OnWebsocketError(*Context, int, string)

	// Start 启动
	Process(wsCtx *Context) error
}

type Request

type Request struct {
	Conn net.Conn
}

func (*Request) Init

func (r *Request) Init(Conn net.Conn)

Init 初始化

func (*Request) RemoteAddr

func (r *Request) RemoteAddr() string

RemoteAddr 请求者 地址

func (*Request) RemoteIp

func (r *Request) RemoteIp() string

RemoteIp 请求者 IP

func (*Request) RemotePort

func (r *Request) RemotePort() uint16

RemotePort 请求者 端口号

type Response

type Response struct {
	Conn net.Conn
}

func (*Response) Close

func (r *Response) Close(content string)

Close 关闭链接

func (*Response) Init

func (r *Response) Init(Conn net.Conn)

Init 初始化

func (*Response) Ping

func (r *Response) Ping(content string)

Ping 发送 ping

func (*Response) Pong

func (r *Response) Pong(content string)

Pong 响应 ping

func (*Response) Write

func (r *Response) Write(content string)

WriteMessage 写数据

Jump to

Keyboard shortcuts

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