Documentation ¶
Index ¶
- type Client
- func (c *Client) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
- func (c *Client) CallOnConnStart(conn netInterface.IConnection)
- func (c *Client) CallOnConnStop(conn netInterface.IConnection)
- func (c *Client) CallOnReceive(conn netInterface.IConnection, data []byte)
- func (c *Client) Close()
- func (c *Client) Connect() (bool, error)
- func (c *Client) GetConn() netInterface.IConnection
- func (c *Client) SendData(data []byte, cmdCode string) error
- func (c *Client) SendDataCall(data []byte, cmdCode string, pram interface{}, ...) error
- func (c *Client) SetCreateReceiver(hookFunc func(netInterface.IConnection, []byte) []netInterface.IReceiver)
- func (c *Client) SetLogHandle(hookFunc func(level netInterface.ErrLevel, msg string))
- func (c *Client) SetOnConnStart(hookFunc func(netInterface.IConnection))
- func (c *Client) SetOnConnStop(hookFunc func(netInterface.IConnection))
- func (c *Client) SetOnReceive(hookFunc func(netInterface.IConnection, []byte))
- type Config
- type Connection
- func (c *Connection) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
- func (c *Connection) CreateReceiver(data []byte) []netInterface.IReceiver
- func (c *Connection) GetConnId() uint64
- func (c *Connection) GetHeartTime() time.Time
- func (c *Connection) GetIsClosed() bool
- func (c *Connection) GetLocalAddr() net.Addr
- func (c *Connection) GetNetConn() interface{}
- func (c *Connection) GetNetwork() string
- func (c *Connection) GetProperty(key string) (interface{}, error)
- func (c *Connection) GetPropertyKeys() []string
- func (c *Connection) GetRecInfo() (count, byteSize uint64)
- func (c *Connection) GetReceiver() []netInterface.IReceiver
- func (c *Connection) GetRemoteAddr() net.Addr
- func (c *Connection) GetRepInfo() (count, byteSize, errCount uint64)
- func (c *Connection) GetStartTime() time.Time
- func (c *Connection) OnCompleted(data []byte, count int)
- func (c *Connection) OnReceive(data []byte)
- func (c *Connection) RemoveProperty(key string)
- func (c *Connection) SendData(data []byte, cmdCode string) error
- func (c *Connection) SendDataCall(data []byte, cmdCode string, 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 {
// contains filtered or unexported fields
}
IServer 接口实现,定义一个Server服务类
func (*Client) CallLogHandle ¶ added in v1.2.0
func (c *Client) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
错误消息处理
func (*Client) CallOnConnStart ¶
func (c *Client) CallOnConnStart(conn netInterface.IConnection)
调用连接OnConnStart Hook函数
func (*Client) CallOnConnStop ¶
func (c *Client) CallOnConnStop(conn netInterface.IConnection)
调用连接OnConnStop Hook函数
func (*Client) CallOnReceive ¶ added in v1.6.1
func (c *Client) CallOnReceive(conn netInterface.IConnection, data []byte)
数据上传完成回调
func (*Client) SendDataCall ¶ added in v1.5.2
func (c *Client) SendDataCall(data []byte, cmdCode string, pram interface{}, callFunc func(netInterface.IConnection, []byte, bool, string, interface{}, error)) error
直接将Message数据发送数据给远程的TCP客户端(带参数和回调)
func (*Client) SetCreateReceiver ¶
func (c *Client) SetCreateReceiver(hookFunc func(netInterface.IConnection, []byte) []netInterface.IReceiver)
设置创建分包策略方法
func (*Client) SetLogHandle ¶ added in v1.2.0
func (c *Client) SetLogHandle(hookFunc func(level netInterface.ErrLevel, msg string))
func (*Client) SetOnConnStart ¶
func (c *Client) SetOnConnStart(hookFunc func(netInterface.IConnection))
设置该client的连接创建时Hook函数
func (*Client) SetOnConnStop ¶
func (c *Client) SetOnConnStop(hookFunc func(netInterface.IConnection))
设置该client的连接断开时的Hook函数
func (*Client) SetOnReceive ¶ added in v1.6.1
func (c *Client) SetOnReceive(hookFunc func(netInterface.IConnection, []byte))
数据上传完成处理函数[分包后]
type Config ¶ added in v1.1.1
type Config struct { Network string //网络类型:tcp,udp Host string //连接的IP和地址 BufferSize uint //缓存尺寸(字节) SendDataCount int //单个连接待发送数据个数 BytesCacheSize int //分包缓存大小 SendOutTime time.Duration //下行超时时间(秒) CertFile string //server.crt 文件路径:TCP支持Tls KeyFile string //server.key 文件路径:TCP支持Tls IsTls bool //是否tls连接 HDataCache bool //是否启用处理数据缓存优化[注意:启用后SetOnReceive 处理方法使用协程会导致数据错乱] OverflowDiscard bool //接收,处理,回复溢出是否丢弃【true:丢弃,false:等待处理】 }
配置
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
连接结构体
func NewConntion ¶
func NewConntion(client *Client, conn net.Conn, config *Config) *Connection
创建连接的方法
func (*Connection) CallLogHandle ¶ added in v1.2.0
func (c *Connection) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
调用异常处理
func (*Connection) CreateReceiver ¶
func (c *Connection) CreateReceiver(data []byte) []netInterface.IReceiver
创建分包器
func (*Connection) GetHeartTime ¶ added in v1.1.1
func (c *Connection) GetHeartTime() time.Time
获取心跳时间
func (*Connection) GetIsClosed ¶ added in v1.4.1
func (c *Connection) GetIsClosed() bool
获取的状态(ture:关闭状态,false:未关闭)
func (*Connection) GetLocalAddr ¶ added in v1.2.2
func (c *Connection) GetLocalAddr() net.Addr
获取本地地址信息
func (*Connection) GetNetConn ¶
func (c *Connection) GetNetConn() interface{}
从当前连接获取原始的socket TCPConn
func (*Connection) GetNetwork ¶ added in v1.6.6
func (c *Connection) GetNetwork() string
GetNetwork 获取网络类型
func (*Connection) GetProperty ¶
func (c *Connection) GetProperty(key string) (interface{}, error)
获取链接属性
func (*Connection) GetPropertyKeys ¶ added in v1.6.3
func (c *Connection) GetPropertyKeys() []string
获取所有属性key
func (*Connection) GetRecInfo ¶ added in v1.4.1
func (c *Connection) GetRecInfo() (count, byteSize uint64)
上行当前处理的包总数(处理前,1开始),总大小(字节)
func (*Connection) GetRepInfo ¶ added in v1.4.1
func (c *Connection) GetRepInfo() (count, byteSize, errCount uint64)
下行当前处理的包总数(处理后),总大小(字节)
func (*Connection) GetStartTime ¶ added in v1.4.1
func (c *Connection) GetStartTime() time.Time
获取连接启动时间
func (*Connection) SendData ¶
func (c *Connection) SendData(data []byte, cmdCode string) error
直接将Message数据发送数据给远程的TCP客户端
func (*Connection) SendDataCall ¶
func (c *Connection) SendDataCall(data []byte, cmdCode string, pram interface{}, callFunc func(netInterface.IConnection, []byte, bool, string, interface{}, error)) error
直接将Message数据发送数据给远程的TCP客户端(带参数和回调)
func (*Connection) SetProperty ¶
func (c *Connection) SetProperty(key string, value interface{})
设置链接属性
type IClient ¶
type IClient interface { SetOnConnStart(hookFunc func(netInterface.IConnection)) //设置连接开始事件 SetOnConnStop(hookFunc func(netInterface.IConnection)) //设置连接停止事件 SetOnReceive(hookFunc func(netInterface.IConnection, []byte)) //设置数据包上传完成事件 SetCreateReceiver(hookFunc func(netInterface.IConnection, []byte) []netInterface.IReceiver) //设置分包策略 SetLogHandle(hookFunc func(level netInterface.ErrLevel, msg string)) //设置内部异常处理 SendData(data []byte, cmdCode string) error //发送消息到客户端: data 下发数据,cmdCode 指令标识[如: rep 普通回复, cmd 用户操作下发 。。] //发送消息到客户端带回调:data 下发数据 param 下发需要回调携带参数 cmdCode 指令标识[如: rep 普通回复, cmd 用户操作下发 。。] callFunc 下发后回调函数 SendDataCall(data []byte, cmdCode string, param interface{}, callFunc func(netInterface.IConnection, []byte, bool, string, interface{}, error)) error GetConn() netInterface.IConnection //获取连接 Connect() (bool, error) //连接 Close() //关闭 }
客户端
Click to show internal directories.
Click to hide internal directories.