Documentation
¶
Index ¶
- type Client
- func (c *Client) CallOnConnStart(conn netConn.IConnection)
- func (c *Client) CallOnConnStop(conn netConn.IConnection)
- func (c *Client) CallOnReceiveCompleted(conn netConn.IConnection, data []byte)
- func (c *Client) Connect() bool
- func (c *Client) GetConn() netConn.IConnection
- func (c *Client) SetCreateReceiver(hookFunc func(netConn.IConnection, []byte) []netConn.IReceiver)
- func (c *Client) SetOnConnStart(hookFunc func(netConn.IConnection))
- func (c *Client) SetOnConnStop(hookFunc func(netConn.IConnection))
- func (c *Client) SetOnReceiveCompleted(hookFunc func(netConn.IConnection, []byte))
- func (c *Client) Stop()
- type Connection
- func (c *Connection) CreateReceiver(data []byte) []netConn.IReceiver
- func (c *Connection) GetBytesCache() *bytes.Buffer
- func (c *Connection) GetConnId() uint64
- func (c *Connection) GetNetConn() net.Conn
- func (c *Connection) GetPackCount() int64
- func (c *Connection) GetProperty(key string) (interface{}, error)
- func (c *Connection) GetReceiver() []netConn.IReceiver
- func (c *Connection) GetRemoteAddr() net.Addr
- func (c *Connection) OnCompleted(data []byte, offset int, count int)
- func (c *Connection) OnReceiveCompleted(data []byte)
- func (c *Connection) RemoveProperty(key string)
- func (c *Connection) SendData(data []byte) error
- func (c *Connection) SendDataCall(data []byte, pram interface{}, ...) error
- func (c *Connection) SetProperty(key string, value interface{})
- func (c *Connection) Start()
- func (c *Connection) Stop()
- type IClient
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) SetCreateReceiver ¶
设置创建分包策略方法
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))
数据上传完成处理函数[分包后]
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 (*Connection) CreateReceiver ¶
func (c *Connection) CreateReceiver(data []byte) []netConn.IReceiver
创建分包器
func (*Connection) GetPackCount ¶
func (c *Connection) GetPackCount() int64
func (*Connection) GetProperty ¶
func (c *Connection) GetProperty(key string) (interface{}, error)
获取链接属性
func (*Connection) OnCompleted ¶
func (c *Connection) OnCompleted(data []byte, offset int, count int)
数据上传处理
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{})
设置链接属性
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() //停止
}
客户端
Click to show internal directories.
Click to hide internal directories.