cli

package
v0.1.50 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: LGPL-2.1 Imports: 29 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrReconnectFailed = errors.New("reconnect failed")
	ErrInactiveTimeout = errors.New("inactive timeout")
)
View Source
var With _Option

Functions

func Reconnect added in v0.1.32

func Reconnect(client *Client) error

Reconnect 重连服务端

Types

type Client

type Client struct {
	context.Context
	// contains filtered or unexported fields
}

Client 客户端

func Connect

func Connect(ctx context.Context, endpoint string, settings ...option.Setting[ClientOptions]) (*Client, error)

Connect 连接服务端

func (*Client) Close

func (c *Client) Close(err error) <-chan struct{}

Close 关闭

func (*Client) GetEndpoint

func (c *Client) GetEndpoint() string

GetEndpoint 获取服务器地址

func (*Client) GetFutures

func (c *Client) GetFutures() concurrent.IFutures

GetFutures 获取异步模型Future控制器

func (*Client) GetLocalAddr

func (c *Client) GetLocalAddr() net.Addr

GetLocalAddr 获取本地地址

func (*Client) GetLogger added in v0.1.36

func (c *Client) GetLogger() *zap.SugaredLogger

GetLogger 获取logger

func (*Client) GetRemoteAddr

func (c *Client) GetRemoteAddr() net.Addr

GetRemoteAddr 获取对端地址

func (*Client) GetSessionId

func (c *Client) GetSessionId() uid.Id

GetSessionId 获取会话Id

func (*Client) GetToken

func (c *Client) GetToken() string

GetToken 获取token

func (*Client) RecvDataChan

func (c *Client) RecvDataChan() <-chan binaryutil.RecycleBytes

RecvDataChan 接收数据的channel

func (*Client) RecvEventChan

func (c *Client) RecvEventChan() <-chan transport.Event[gtp.Msg]

RecvEventChan 接收自定义事件的channel

func (*Client) RequestTime

func (c *Client) RequestTime(ctx context.Context) concurrent.Reply[*ResponseTime]

RequestTime 请求对端同步时间

func (*Client) SendData

func (c *Client) SendData(data []byte) error

SendData 发送数据

func (*Client) SendDataChan

func (c *Client) SendDataChan() chan<- binaryutil.RecycleBytes

SendDataChan 发送数据的channel

func (*Client) SendEvent

func (c *Client) SendEvent(event transport.Event[gtp.MsgReader]) error

SendEvent 发送自定义事件

func (*Client) SendEventChan

func (c *Client) SendEventChan() chan<- transport.Event[gtp.MsgReader]

SendEventChan 发送自定义事件的channel

func (*Client) String

func (c *Client) String() string

String implements fmt.Stringer

func (*Client) WatchData

func (c *Client) WatchData(ctx context.Context, handler RecvDataHandler) IWatcher

WatchData 监听数据

func (*Client) WatchEvent

func (c *Client) WatchEvent(ctx context.Context, handler RecvEventHandler) IWatcher

WatchEvent 监听自定义事件

type ClientOptions

type ClientOptions struct {
	NetProtocol                 NetProtocol                         // 使用的网络协议(TCP/WebSocket)
	TCPNoDelay                  *bool                               // TCP的NoDelay选项,nil表示使用系统默认值
	TCPQuickAck                 *bool                               // TCP的QuickAck选项,nil表示使用系统默认值
	TCPRecvBuf                  *int                                // TCP的RecvBuf大小(字节)选项,nil表示使用系统默认值
	TCPSendBuf                  *int                                // TCP的SendBuf大小(字节)选项,nil表示使用系统默认值
	TCPLinger                   *int                                // TCP的PLinger选项,nil表示使用系统默认值
	WebSocketOrigin             string                              // WebSocket的Origin地址,不填将会自动生成
	TLSConfig                   *tls.Config                         // TLS配置,nil表示不使用TLS加密链路
	IOTimeout                   time.Duration                       // 网络io超时时间
	IORetryTimes                int                                 // 网络io超时后的重试次数
	IOBufferCap                 int                                 // 网络io缓存容量(字节)
	DecoderMsgCreator           gtp.IMsgCreator                     // 消息包解码器的消息构建器
	EncCipherSuite              gtp.CipherSuite                     // 加密通信中的密码学套件
	EncSignatureAlgorithm       gtp.SignatureAlgorithm              // 加密通信中的签名算法
	EncSignaturePrivateKey      crypto.PrivateKey                   // 加密通信中,签名用的私钥
	EncVerifyServerSignature    bool                                // 加密通信中,是否验证服务端签名
	EncVerifySignaturePublicKey crypto.PublicKey                    // 加密通信中,验证服务端签名用的公钥
	Compression                 gtp.Compression                     // 通信中的压缩函数
	CompressedSize              int                                 // 通信中启用压缩阀值(字节),<=0表示不开启
	AutoReconnect               bool                                // 开启自动重连
	AutoReconnectInterval       time.Duration                       // 自动重连的时间间隔
	AutoReconnectRetryTimes     int                                 // 自动重连的重试次数,<=0表示无限重试
	InactiveTimeout             time.Duration                       // 连接不活跃后的超时时间,开启自动重连后无效
	SendDataChan                chan binaryutil.RecycleBytes        // 发送数据的channel
	RecvDataChan                chan binaryutil.RecycleBytes        // 接收数据的channel
	RecvDataChanRecyclable      bool                                // 接收数据的channel中是否使用可回收字节对象
	SendEventChan               chan transport.Event[gtp.MsgReader] // 发送自定义事件的channel
	RecvEventChan               chan transport.Event[gtp.Msg]       // 接收自定义事件的channel
	RecvDataHandler             RecvDataHandler                     // 接收的数据的处理器
	RecvEventHandler            RecvEventHandler                    // 接收的自定义事件的处理器
	FutureTimeout               time.Duration                       // 异步模型Future超时时间
	AuthUserId                  string                              // 鉴权userid
	AuthToken                   string                              // 鉴权token
	AuthExtensions              []byte                              // 鉴权extensions
	ZapLogger                   *zap.Logger                         // zap日志
}

type IWatcher added in v0.1.36

type IWatcher interface {
	context.Context
	Terminate() <-chan struct{}
}

IWatcher 监听器

type NetProtocol added in v0.1.40

type NetProtocol int32
const (
	TCP NetProtocol = iota
	WebSocket
)

type RecvDataHandler

type RecvDataHandler = generic.DelegateFunc1[[]byte, error]

type RecvEventHandler

type RecvEventHandler = transport.EventHandler

type ResponseTime

type ResponseTime struct {
	RequestTime time.Time // 请求时的本地时间
	LocalTime   time.Time // 响应时的本地时间
	RemoteTime  time.Time // 响应时的对端时间
}

ResponseTime 响应同步时间

func (*ResponseTime) NowTime

func (rt *ResponseTime) NowTime() time.Time

NowTime 当前时间

func (*ResponseTime) RTT

func (rt *ResponseTime) RTT() time.Duration

RTT 往返时间

func (*ResponseTime) SyncTime

func (rt *ResponseTime) SyncTime() time.Time

SyncTime 同步的时间

Jump to

Keyboard shortcuts

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