gsws

package
v1.9.9 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Host string
	Port string
	Uri  string //路由

	ReadBufferSize  int  //IO读缓冲区
	WriteBufferSize int  //IO写缓冲区
	CheckOrigin     bool //是否检查跨域 true:不允许跨域,false:允许跨域

	MaxLiveTime      int64         //连接最大生存时间 心跳要小于这个值
	MaxWriteWaitTime time.Duration //推送消息最大等待时间
	MaxReadWaitTime  time.Duration //读取消息最大的等待时间
	MaxMessageSize   int64         //消息最大byte

	MaxClient int //最大的客户端数

}

type GsMessageItem

type GsMessageItem struct {
	Type int    `json:"type"`
	Msg  string `json:"msg"`
}

GsMessageItem 消息体

type GsWsClient

type GsWsClient struct {
	Host       string
	Port       string
	Uri        string
	RecMsgChan chan string
	CallFunc   func(string) string
}

func (*GsWsClient) SetCallFunc

func (h *GsWsClient) SetCallFunc(callFunc func(string) string)

SetCallFunc 设置回调

func (*GsWsClient) Start

func (h *GsWsClient) Start() error

type Message

type Message struct {
	WebsocketMessageType int64 //websocket的消息类型
	Data                 string
}

Message 客户端读写消息

type Server

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

Server 服务总配置

func (*Server) SetConfig

func (h *Server) SetConfig(conf Config)

SetConfig 设置配置

func (*Server) SetConnCloseFunc

func (h *Server) SetConnCloseFunc(closeFunc func(clientId string))

SetConnCloseFunc 连接关闭回调

func (*Server) SetGClientIdFunc

func (h *Server) SetGClientIdFunc(getClientIdFunc func() string)

SetGClientIdFunc 获取clientId回调

func (*Server) SetNewConnFunc

func (h *Server) SetNewConnFunc(newCliConnFunc func(wsConn *WsConn, queryParams map[string]any))

SetNewConnFunc 新连接回调

func (*Server) Start

func (h *Server) Start() error

Start 启动

type WsConn

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

WsConn 客户端连接配置

func (*WsConn) GetClientId

func (h *WsConn) GetClientId() string

GetClientId 返回客户端ID

func (*WsConn) IsConnected

func (h *WsConn) IsConnected() bool

IsConnected 客户端是否在连接中

func (*WsConn) SendMessage

func (h *WsConn) SendMessage(backMsg string) error

SendMessage 写入消息到队列中

func (*WsConn) SetReceiveFunc

func (h *WsConn) SetReceiveFunc(receiveFunc func(message string))

SetReceiveFunc 设置回调方法

Jump to

Keyboard shortcuts

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