netClient

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2020 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Network            string                                                          //网络类型:tcp  udp
	IP                 string                                                          //服务绑定的IP地址
	Port               int                                                             //服务绑定的端口
	OnConnStart        func(conn netConn.IConnection)                                  //创建时Hook函数
	OnConnStop         func(conn netConn.IConnection)                                  //连接断开时的Hook函数
	OnReceiveCompleted func(conn netConn.IConnection, data []byte)                     //数据上传完成
	CreateReceiver     func(conn netConn.IConnection, data []byte) []netConn.IReceiver //数据分包
	Conn               *Connection                                                     //连接
	BufferPool         *util.BufferPool                                                //缓存管理器
}

IServer 接口实现,定义一个Server服务类

func (*Client) CallOnConnStart

func (c *Client) CallOnConnStart(conn netConn.IConnection)

调用连接OnConnStart Hook函数

func (*Client) CallOnConnStop

func (c *Client) CallOnConnStop(conn netConn.IConnection)

调用连接OnConnStop Hook函数

func (*Client) CallOnReceiveCompleted

func (c *Client) CallOnReceiveCompleted(conn netConn.IConnection, data []byte)

数据上传完成回调

func (*Client) Connect

func (c *Client) Connect() bool

连接到服务

func (*Client) GetConn

func (c *Client) GetConn() netConn.IConnection

获取客户端连接

func (*Client) SetCreateReceiver

func (c *Client) SetCreateReceiver(hookFunc func(netConn.IConnection, []byte) []netConn.IReceiver)

设置创建分包策略方法

func (*Client) SetOnConnStart

func (c *Client) SetOnConnStart(hookFunc func(netConn.IConnection))

设置该client的连接创建时Hook函数

func (*Client) SetOnConnStop

func (c *Client) SetOnConnStop(hookFunc func(netConn.IConnection))

设置该client的连接断开时的Hook函数

func (*Client) SetOnReceiveCompleted

func (c *Client) SetOnReceiveCompleted(hookFunc func(netConn.IConnection, []byte))

数据上传完成处理函数[分包后]

func (*Client) Stop

func (c *Client) Stop()

关闭

type Connection

type Connection struct {
	Client *Client  //当前conn属于哪个client,在conn初始化的时候添加即可
	Conn   net.Conn //连接客户端

	ExitBuffChan chan bool //告知该链接已经退出/停止的channel(管道)

	HeartTime time.Time //心跳时间
	PackCount int64     //包个数
	// contains filtered or unexported fields
}

连接结构体

func NewConntion

func NewConntion(client *Client, conn net.Conn) *Connection

创建连接的方法

func (*Connection) CreateReceiver

func (c *Connection) CreateReceiver(data []byte) []netConn.IReceiver

创建分包器

func (*Connection) GetBytesCache

func (c *Connection) GetBytesCache() *bytes.Buffer

获取缓存

func (*Connection) GetConnId

func (c *Connection) GetConnId() uint64

获取客户端ID

func (*Connection) GetNetConn

func (c *Connection) GetNetConn() net.Conn

从当前连接获取原始的socket TCPConn

func (*Connection) GetPackCount

func (c *Connection) GetPackCount() int64

func (*Connection) GetProperty

func (c *Connection) GetProperty(key string) (interface{}, error)

获取链接属性

func (*Connection) GetReceiver

func (c *Connection) GetReceiver() []netConn.IReceiver

获取分包器

func (*Connection) GetRemoteAddr

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

获取远程客户端地址信息

func (*Connection) OnCompleted

func (c *Connection) OnCompleted(data []byte, offset int, count int)

数据上传处理

func (*Connection) OnReceiveCompleted

func (c *Connection) OnReceiveCompleted(data []byte)

数据分包完成

func (*Connection) RemoveProperty

func (c *Connection) RemoveProperty(key string)

移除链接属性

func (*Connection) SendData

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

直接将Message数据发送数据给远程的TCP客户端

func (*Connection) SendDataCall

func (c *Connection) SendDataCall(data []byte, pram interface{}, callFunc func(netConn.IConnection, bool, interface{}, error)) error

直接将Message数据发送数据给远程的TCP客户端(带参数和回调)

func (*Connection) SetProperty

func (c *Connection) SetProperty(key string, value interface{})

设置链接属性

func (*Connection) Start

func (c *Connection) Start()

启动连接,让当前连接开始工作

func (*Connection) Stop

func (c *Connection) Stop()

停止连接,结束当前连接状态M

type IClient

type IClient interface {
	SetOnConnStart(hookFunc func(netConn.IConnection))                                //设置连接开始事件
	SetOnConnStop(hookFunc func(netConn.IConnection))                                 //设置连接停止事件
	SetOnReceiveCompleted(hookFunc func(netConn.IConnection, []byte))                 //设置数据包上传完成事件
	SetCreateReceiver(hookFunc func(netConn.IConnection, []byte) []netConn.IReceiver) //设置分包策略
	GetConn() netConn.IConnection                                                     //获取连接
	Connect() bool                                                                    //连接
	Stop()                                                                            //停止
}

客户端

func NewClient

func NewClient(network string, ip string, port int) IClient

创建一个客户端对象

Jump to

Keyboard shortcuts

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