client

package
v0.0.0-...-68bdf18 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2018 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AsyncClient

type AsyncClient struct {
	Ip   string
	Port int

	HeartBeatRspTs int64 //上次收到心跳回复的时间戳,两个G使用,故原子操作
	// contains filtered or unexported fields
}

func CreateAsyncClient

func CreateAsyncClient(ip string, port int, enableHeartBeat bool) *AsyncClient

创建一个client结构体

func (*AsyncClient) Connect

func (c *AsyncClient) Connect() error

执行连接

func (*AsyncClient) HeartbeatProbe

func (c *AsyncClient) HeartbeatProbe()

心跳检测G

func (*AsyncClient) RegHandler

func (c *AsyncClient) RegHandler(cmdId uint, handler MsgHandler)

设置消息ID对应的回调

func (*AsyncClient) Send

func (c *AsyncClient) Send(cmdId uint, pb proto.Message) bool

发送消息

func (*AsyncClient) SetFactory

func (c *AsyncClient) SetFactory(f PacketFactory)

设置消息ID与消息PB的映射函数

func (*AsyncClient) Wait

func (c *AsyncClient) Wait()

等待连接关闭

type MsgHandler

type MsgHandler func(*AsyncClient, proto.Message)

遇到某消息ID的回调函数类型

type PacketFactory

type PacketFactory func(uint) proto.Message

消息ID与消息PB的映射函数类型

type SendTask

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

待发送数据

type SyncClient

type SyncClient struct {
	Ip   string
	Port int
	// contains filtered or unexported fields
}

func CreateSyncClient

func CreateSyncClient(ip string, port int) (*SyncClient, error)

创建一个client结构体并连接

func (*SyncClient) Close

func (c *SyncClient) Close()

关闭连接

func (*SyncClient) Read

func (c *SyncClient) Read(timeout time.Duration, cmdId uint, packet proto.Message) error

收消息,指定消息头、消息PB类型

func (*SyncClient) Send

func (c *SyncClient) Send(cmdId uint, pb proto.Message) error

发送消息

Jump to

Keyboard shortcuts

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