websocketPool

package
v2.14.0 Latest Latest
Warning

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

Go to latest
Published: Sep 12, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ServerPoolApp    ServerPool
	SeverInstanceApp ServerInstance
)

Functions

func ClientDemo added in v2.13.0

func ClientDemo()

func ServerDemo added in v2.13.0

func ServerDemo()

Types

type Client added in v2.12.3

type Client struct {
	Conn *websocket.Conn
	// contains filtered or unexported fields
}

Client websocket 客户端链接

func (Client) New added in v2.12.3

func (Client) New(host, path string, receiveMessageFunc func(string, []byte)) (*Client, error)

New 实例化:websocket 客户端链接

type ClientInstance added in v2.12.3

type ClientInstance struct {
	Connections *dict.AnyDict[string, *Client]
}

ClientInstance websocket 客户端链接实例

func (*ClientInstance) GetClient added in v2.12.3

func (r *ClientInstance) GetClient(clientName string) (*websocket.Conn, bool)

GetClient 获取websocket客户端链接

func (ClientInstance) New added in v2.12.3

New 实例化:websocket 客户端实例

type ClientPool added in v2.12.2

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

ClientPool websocket 客户端连接池

var (
	ClientPoolApp ClientPool
)

func (ClientPool) Close added in v2.12.3

func (ClientPool) Close() error

Close 关闭客户端实例池

func (ClientPool) CloseClient added in v2.12.3

func (ClientPool) CloseClient(instanceName, clientName string)

CloseClient 关闭链接

func (ClientPool) CloseInstance added in v2.12.3

func (ClientPool) CloseInstance(instanceName string) error

CloseInstance 关闭实例

func (ClientPool) GetClientInstance added in v2.12.3

func (ClientPool) GetClientInstance(instanceName string) (*ClientInstance, bool)

GetClientInstance 获取链接实例

func (ClientPool) Once added in v2.12.3

func (ClientPool) Once() *ClientPool

Once 单例化:websocket 客户端连接池

func (ClientPool) SendMessageByConn added in v2.13.3

func (ClientPool) SendMessageByConn(client *Client, message string, isSync bool) ([]byte, error)

SendMessageByConn 发送消息:通过链接

func (ClientPool) SendMessageByName added in v2.13.3

func (ClientPool) SendMessageByName(instanceName, clientName, message string, isSync bool) ([]byte, error)

SendMessageByName 发送消息:通过名称

func (ClientPool) SetClient added in v2.12.3

func (ClientPool) SetClient(
	instanceName,
	clientName,
	host,
	path string,
	receiveMessageFunc func(string, []byte),
	heartInterval time.Duration,
	heartFn func(*Client),
) error

SetClient 设置websocket客户端链接

func (ClientPool) SetOnCloseClientErr added in v2.12.3

func (ClientPool) SetOnCloseClientErr(fn func(string, error)) *ClientPool

SetOnCloseClientErr 设置回调:关闭客户端链接错

func (ClientPool) SetOnConnect added in v2.12.4

func (ClientPool) SetOnConnect(fn func(string)) *ClientPool

SetOnConnect 设置回调:成功创建链接

func (ClientPool) SetOnConnectErr added in v2.12.4

func (ClientPool) SetOnConnectErr(fn func(string, error)) *ClientPool

SetOnConnectErr 设置回调:链接错误

func (ClientPool) SetOnReceiveMessageErr added in v2.12.3

func (ClientPool) SetOnReceiveMessageErr(fn func(string, []byte, error)) *ClientPool

SetOnReceiveMessageErr 设置回调:接收消息错误

func (ClientPool) SetOnSendMessageErr added in v2.12.4

func (ClientPool) SetOnSendMessageErr(fn func(error)) *ClientPool

SetOnSendMessageErr 设置回调:发送消息错误

type ResponseWrt added in v2.13.1

type ResponseWrt struct{}

func (ResponseWrt) Header added in v2.13.1

func (ResponseWrt) Header() http.Header

func (ResponseWrt) Write added in v2.13.1

func (ResponseWrt) Write([]byte) (int, error)

func (ResponseWrt) WriteHeader added in v2.13.1

func (ResponseWrt) WriteHeader(statusCode int)

type Server added in v2.13.0

type Server struct {
	Conn *websocket.Conn
	// contains filtered or unexported fields
}

Server websocket服务端链接

type ServerInstance added in v2.12.3

type ServerInstance struct {
	Connections *array.AnyArray[*Server]
}

ServerInstance websocket服务端实例

func (ServerInstance) New added in v2.12.3

New 实例化:链接切片

type ServerPool added in v2.12.1

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

ServerPool websocket 服务端连接池

func (ServerPool) Close added in v2.12.1

func (ServerPool) Close()

Close 关闭连接池

func (ServerPool) Handle added in v2.12.1

func (ServerPool) Handle(
	writer http.ResponseWriter,
	req *http.Request,
	header http.Header,
	condition func() (string, bool),
)

Handle 消息处理

func (ServerPool) Once added in v2.12.1

func (ServerPool) Once() *ServerPool

Once 单例化:服务端连接池

func (ServerPool) RegisterRouter added in v2.12.1

func (ServerPool) RegisterRouter(routerKey string, fn func(ws *websocket.Conn)) *ServerPool

RegisterRouter 注册路由

func (ServerPool) SendMessageByAccountOpenId added in v2.12.1

func (ServerPool) SendMessageByAccountOpenId(accountOpenId string, message []byte) error

SendMessageByAccountOpenId 根据用户openId发送消息

func (ServerPool) SendMessageByWsConn added in v2.12.1

func (ServerPool) SendMessageByWsConn(ws *websocket.Conn, message []byte) error

SendMessageByWsConn 通过链接发送消息

func (ServerPool) SendMessageByWsManyConn added in v2.12.1

func (ServerPool) SendMessageByWsManyConn(servers *array.AnyArray[*Server], message []byte)

SendMessageByWsManyConn 通过链接切片发送消息

func (ServerPool) SetOnCloseConnectionErr added in v2.12.1

func (ServerPool) SetOnCloseConnectionErr(onCloseConnectionErr func(conn *websocket.Conn, err error)) *ServerPool

SetOnCloseConnectionErr 设置回调:关闭链接错误

func (ServerPool) SetOnConnect added in v2.12.1

func (ServerPool) SetOnConnect(onConnect func(*websocket.Conn)) *ServerPool

SetOnConnect 设置回调:链接成功后

func (ServerPool) SetOnConnectErr added in v2.12.4

func (ServerPool) SetOnConnectErr(onConnectionErr func(error)) *ServerPool

SetOnConnectErr 设置回调:链接失败后

func (ServerPool) SetOnPing added in v2.12.6

func (ServerPool) SetOnPing(fn func(*websocket.Conn)) *ServerPool

SetOnPing 设置回调:ping

func (ServerPool) SetOnReceiveMessage added in v2.12.4

func (ServerPool) SetOnReceiveMessage(onMessage func(*websocket.Conn, []byte) string) *ServerPool

SetOnReceiveMessage 设置回调:接收消息

func (ServerPool) SetOnReceiveMessageErr added in v2.12.4

func (ServerPool) SetOnReceiveMessageErr(onMessageErr func(*websocket.Conn, error)) *ServerPool

SetOnReceiveMessageErr 设置回调:接收消息失败

func (ServerPool) SetOnRouterErr added in v2.12.1

func (ServerPool) SetOnRouterErr(onRouterErr func(*websocket.Conn, error)) *ServerPool

SetOnRouterErr 设置回调:路由解析失败

func (ServerPool) SetOnSendMessageErr added in v2.12.1

func (ServerPool) SetOnSendMessageErr(onSendMessageErr func(conn *websocket.Conn, err error)) *ServerPool

SetOnSendMessageErr 设置回调:发送消息失败

Jump to

Keyboard shortcuts

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