websocketPool

package
v2.17.6 Latest Latest
Warning

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

Go to latest
Published: Oct 8, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ClientPoolApp     ClientPool
	ClientInstanceApp ClientInstance

	HeartOpt          Heart
	MessageTimeoutOpt MessageTimeout
)
View Source
var (
	ServerPoolApp    ServerPool
	SeverInstanceApp ServerInstance
)
View Source
var MsgType msgType

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 {
	InstanceName, Name string
	Conn               *websocket.Conn
	// contains filtered or unexported fields
}

Client websocket 客户端链接

func NewClient added in v2.14.20

func NewClient(instanceName, name, host, path string, receiveMessageFunc func(instanceName, clientName string, prototypeMsg []byte) ([]byte, error)) (*Client, error)

NewClient 实例化:websocket 客户端链接

func (*Client) Close added in v2.14.4

func (r *Client) Close() error

Close 关闭链接

func (*Client) SendMsg added in v2.14.11

func (r *Client) SendMsg(msgType int, msg []byte) ([]byte, error)

SendMsg 发送消息:通过链接

type ClientInstance added in v2.12.3

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

ClientInstance websocket 客户端链接实例

func (*ClientInstance) Close added in v2.14.4

func (r *ClientInstance) Close()

Close 关闭客户端实例

func (*ClientInstance) GetClient added in v2.12.3

func (r *ClientInstance) GetClient(clientName string) (*Client, bool)

GetClient 获取websocket客户端链接

func (ClientInstance) New added in v2.12.3

func (ClientInstance) New(instanceName string) *ClientInstance

New 实例化:websocket 客户端实例

func (*ClientInstance) SendMsgByName added in v2.14.20

func (r *ClientInstance) SendMsgByName(clientName string, msgType int, msg []byte) ([]byte, error)

SendMsgByName 发送消息:通过名称

func (*ClientInstance) SetClient added in v2.14.2

func (r *ClientInstance) SetClient(
	clientName, host, path string,
	receiveMessageFn func(instanceName, clientName string, propertyMessage []byte) ([]byte, error),
	heart *Heart,
	timeout *MessageTimeout,
) (*Client, error)

SetClient 创建新链接

type ClientPool added in v2.12.2

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

ClientPool websocket 客户端连接池

func (ClientPool) Close added in v2.12.3

func (ClientPool) Close()

Close 关闭客户端实例池

func (ClientPool) CloseClient added in v2.12.3

func (ClientPool) CloseClient(instanceName, clientName string) error

CloseClient 关闭链接

func (ClientPool) GetClient added in v2.14.8

func (ClientPool) GetClient(instanceName, clientName string) *Client

GetClient 获取客户端链接

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) SendMsgByName added in v2.14.11

func (ClientPool) SendMsgByName(instanceName, clientName string, msgType int, msg []byte) ([]byte, error)

SendMsgByName 发送消息:通过名称

func (ClientPool) SetClient added in v2.12.3

func (ClientPool) SetClient(
	instanceName,
	clientName,
	host,
	path string,
	receiveMessageFn func(instanceName, clientName string, prototypeMsg []byte) ([]byte, error),
	heart *Heart,
	timeout *MessageTimeout,
) (*Client, error)

SetClient 设置websocket客户端链接

func (ClientPool) SetClientInstance added in v2.14.2

func (ClientPool) SetClientInstance(instanceName string) (*ClientInstance, error)

SetClientInstance 设置实例链接

func (ClientPool) SetOnCloseClientErr added in v2.12.3

func (ClientPool) SetOnCloseClientErr(fn func(instanceName, clientName string, err error)) *ClientPool

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

func (ClientPool) SetOnConnect added in v2.12.4

func (ClientPool) SetOnConnect(fn func(instanceName, clientName string)) *ClientPool

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

func (ClientPool) SetOnConnectErr added in v2.12.4

func (ClientPool) SetOnConnectErr(fn func(instanceName, clientName string, err error)) *ClientPool

SetOnConnectErr 设置回调:链接错误

func (ClientPool) SetOnReceiveMsgErr added in v2.14.11

func (ClientPool) SetOnReceiveMsgErr(fn func(instanceName, clientName string, propertyMessage []byte, err error)) *ClientPool

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

func (ClientPool) SetOnSendMsgErr added in v2.14.11

func (ClientPool) SetOnSendMsgErr(fn func(instanceName, clientName string, err error)) *ClientPool

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

type Heart added in v2.14.4

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

Heart 链接心跳

func (Heart) Default added in v2.14.6

func (Heart) Default() *Heart

Default 默认心跳:10秒

func (Heart) New added in v2.14.4

func (Heart) New() *Heart

New 实例化:链接心跳

func (*Heart) SetFn added in v2.14.6

func (r *Heart) SetFn(fn func(client *Client)) *Heart

SetFn 设置回调:定时器执行内容

func (*Heart) SetInterval added in v2.14.6

func (r *Heart) SetInterval(interval time.Duration) *Heart

SetInterval 设置定时器

func (*Heart) Stop added in v2.14.6

func (r *Heart) Stop() *Heart

Stop 停止定时器

type MessageTimeout added in v2.14.1

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

MessageTimeout 通信超时

func (MessageTimeout) Default added in v2.14.6

func (MessageTimeout) Default() *MessageTimeout

Default 默认消息超时:5秒

func (MessageTimeout) New added in v2.14.1

New 实例化:链接超时

func (*MessageTimeout) SetInterval added in v2.14.6

func (r *MessageTimeout) SetInterval(interval time.Duration) *MessageTimeout

SetInterval 设置定时器时间

type PendingRequest added in v2.14.20

type PendingRequest struct {
	Uuid uuid.UUID
	Chan chan []byte
	Done chan struct{}
	Err  error
}

PendingRequest

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) SendMsgByAccountOpenId added in v2.14.11

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

SendMsgByAccountOpenId 根据用户openId发送消息

func (ServerPool) SendMsgByWsConn added in v2.14.10

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

SendMsgByWsConn 通过链接发送消息

func (ServerPool) SendMsgByWsManyConn added in v2.14.11

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

SendMsgByWsManyConn 通过链接切片发送消息

func (ServerPool) SetOnCloseConnErr added in v2.14.10

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

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

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(onConnectErr func(error)) *ServerPool

SetOnConnectErr 设置回调:链接失败后

func (ServerPool) SetOnPing added in v2.12.6

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

SetOnPing 设置回调:ping

func (ServerPool) SetOnReceiveMsg added in v2.14.10

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

SetOnReceiveMsg 设置回调:接收消息

func (ServerPool) SetOnReceiveMsgErr added in v2.14.10

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

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

func (ServerPool) SetOnRouterErr added in v2.12.1

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

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

func (ServerPool) SetOnSendMsgErr added in v2.14.10

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

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

Jump to

Keyboard shortcuts

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