client

package
v0.0.0-...-799f385 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2024 License: MIT Imports: 14 Imported by: 1

Documentation

Index

Constants

View Source
const (
	ReqeustTimeout = 15 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CBTask

type CBTask func(error bool, msg *message.Message)

type Client

type Client struct {
	Connected bool
	// 握手完毕
	Ready bool

	IncomingMsgChan chan *ClientMsg
	// contains filtered or unexported fields
}

Client 重连在上层处理 携程

readServerMessages
		读取消息
		组织成packet
handlePackets
		处理packet
sendHeartbeats
		定时发送heartbeat
pendingRequestsReaper
		移除超时未返回的请求

func New

func New(requestTimeout ...time.Duration) *Client

New returns a new client

func (*Client) ConnectTo

func (c *Client) ConnectTo(addr string) error

ConnectTo connects to the server at addr, for now the only supported protocol is tcp this methods blocks as it also handles the messages from the server

func (*Client) ConnectToTLS

func (c *Client) ConnectToTLS(addr string, skipVerify bool) error

ConnectToTLS connects to the server at addr using TLS, for now the only supported protocol is tcp this methods blocks as it also handles the messages from the server

func (*Client) ConnectedStatus

func (c *Client) ConnectedStatus() bool

ConnectedStatus return the connection status

func (*Client) Disconnect

func (c *Client) Disconnect()

Disconnect disconnects the client

func (*Client) MsgChannel

func (c *Client) MsgChannel() chan *ClientMsg

MsgChannel return the incoming message channel

func (*Client) SendNotify

func (c *Client) SendNotify(route string, data []byte) error

SendNotify sends a notify to the server

func (*Client) SendRequest

func (c *Client) SendRequest(route string, data []byte, cb CBTask) (uint, error)

SendRequest sends a request to the server

func (*Client) WaitReady

func (c *Client) WaitReady()

等待连接完毕

type ClientMsg

type ClientMsg struct {
	Msg *message.Message
	Cb  CBTask
}

type HandshakeData

type HandshakeData struct {
	Code int          `json:"code"`
	Sys  HandshakeSys `json:"sys"`
}

HandshakeData struct

type HandshakeSys

type HandshakeSys struct {
	Dict       map[string]uint16 `json:"dict"`
	Heartbeat  int               `json:"heartbeat"`
	Serializer string            `json:"serializer"`
}

HandshakeSys struct

Jump to

Keyboard shortcuts

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