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) SetHandleStrategy(hookFunc func(netInterface.IConnection, []byte) *netInterface.StrategyData)
- 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) 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) GetRemoteAddr() net.Addr
- func (c *Connection) GetRepInfo() (count, byteSize, errCount uint64)
- func (c *Connection) GetSendTime() time.Time
- func (c *Connection) GetStartTime() time.Time
- func (c *Connection) Incr(val int64) int64
- 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
}
Client 接口实现,定义一个Server服务类
func (*Client) CallLogHandle ¶ added in v1.2.0
func (c *Client) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
CallLogHandle 错误消息处理
func (*Client) CallOnConnStart ¶
func (c *Client) CallOnConnStart(conn netInterface.IConnection)
CallOnConnStart 调用连接OnConnStart Hook函数
func (*Client) CallOnConnStop ¶
func (c *Client) CallOnConnStop(conn netInterface.IConnection)
CallOnConnStop 调用连接OnConnStop Hook函数
func (*Client) CallOnReceive ¶ added in v1.6.1
func (c *Client) CallOnReceive(conn netInterface.IConnection, data []byte)
CallOnReceive 数据上传完成回调
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
SendDataCall 发送数据给远程的TCP客户端(带参数和回调)
func (*Client) SetHandleStrategy ¶ added in v1.8.17
func (c *Client) SetHandleStrategy(hookFunc func(netInterface.IConnection, []byte) *netInterface.StrategyData)
SetHandleStrategy 设置处理策略
func (*Client) SetLogHandle ¶ added in v1.2.0
func (c *Client) SetLogHandle(hookFunc func(level netInterface.ErrLevel, msg string))
SetLogHandle 设置日志输出
func (*Client) SetOnConnStart ¶
func (c *Client) SetOnConnStart(hookFunc func(netInterface.IConnection))
SetOnConnStart 设置该client的连接创建时Hook函数
func (*Client) SetOnConnStop ¶
func (c *Client) SetOnConnStop(hookFunc func(netInterface.IConnection))
SetOnConnStop 设置该client的连接断开时的Hook函数
func (*Client) SetOnReceive ¶ added in v1.6.1
func (c *Client) SetOnReceive(hookFunc func(netInterface.IConnection, []byte))
SetOnReceive 数据上传完成处理函数[分包后]
type Config ¶ added in v1.1.1
type Config struct { Network string //网络类型:tcp,udp Host string //连接的IP和地址 BufferSize int //缓存尺寸(字节) SendDataCount int //单个连接待发送数据个数[注:OverflowDiscard为true时,超过则丢弃] SendOutTime time.Duration //下行超时时间(秒) OverflowDiscard bool //接收,处理,回复溢出是否丢弃【true:丢弃,false:等待处理】 IsTls bool //是否启用tls连接 TlsConfig *tls.Config //tls配置 SendRetryCount int //发送遇到临时错误失败重试次数 HDataCache bool //默认 true, 注意:调用 SetOnReceive 的方法是否新申请内存[false:新申请内存,处理函数可以另外开启协程处理;true:不申请新内存,处理函数不可以另外开启协程处理] }
Config 配置
func DefaultConfig ¶ added in v1.3.0
DefaultConfig 默认配置
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection 连接结构体
func NewConnection ¶ added in v1.8.16
func NewConnection(client *Client, conn net.Conn, config *Config) *Connection
NewConnection 创建连接的方法
func (*Connection) CallLogHandle ¶ added in v1.2.0
func (c *Connection) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
CallLogHandle 调用异常处理
func (*Connection) GetHeartTime ¶ added in v1.1.1
func (c *Connection) GetHeartTime() time.Time
GetHeartTime 连接最后一次接收数据时间
func (*Connection) GetIsClosed ¶ added in v1.4.1
func (c *Connection) GetIsClosed() bool
GetIsClosed 获取的状态[脏读](ture:关闭状态,false:未关闭)
func (*Connection) GetLocalAddr ¶ added in v1.2.2
func (c *Connection) GetLocalAddr() net.Addr
GetLocalAddr 获取本地地址信息
func (*Connection) GetNetConn ¶
func (c *Connection) GetNetConn() interface{}
GetNetConn 从当前连接获取原始的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)
GetProperty 获取链接属性
func (*Connection) GetPropertyKeys ¶ added in v1.6.3
func (c *Connection) GetPropertyKeys() []string
GetPropertyKeys 获取所有属性key
func (*Connection) GetRecInfo ¶ added in v1.4.1
func (c *Connection) GetRecInfo() (count, byteSize uint64)
GetRecInfo 上行当前处理的包总数(处理前,1开始),总大小(字节)
func (*Connection) GetRemoteAddr ¶
func (c *Connection) GetRemoteAddr() net.Addr
GetRemoteAddr 获取远程客户端地址信息
func (*Connection) GetRepInfo ¶ added in v1.4.1
func (c *Connection) GetRepInfo() (count, byteSize, errCount uint64)
GetRepInfo 下行当前处理的包总数(处理后),总大小(字节)
func (*Connection) GetSendTime ¶ added in v1.8.17
func (c *Connection) GetSendTime() time.Time
GetSendTime 连接最后一次发送数据时间
func (*Connection) GetStartTime ¶ added in v1.4.1
func (c *Connection) GetStartTime() time.Time
GetStartTime 连接建立时间
func (*Connection) Incr ¶ added in v1.8.7
func (c *Connection) Incr(val int64) int64
Incr 连接提供给业务作为流水号使用,循环累加,(val 为正数为递增,val为负数为递减,val为0则获取值)
func (*Connection) OnCompleted ¶
func (c *Connection) OnCompleted(data []byte, count int)
OnCompleted 数据上传处理
func (*Connection) OnReceive ¶ added in v1.6.1
func (c *Connection) OnReceive(data []byte)
OnReceive 数据分包完成
func (*Connection) RemoveProperty ¶
func (c *Connection) RemoveProperty(key string)
RemoveProperty 移除链接属性
func (*Connection) SendData ¶
func (c *Connection) SendData(data []byte, cmdCode string) error
SendData 直接将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
SendDataCall 直接将Message数据发送数据给远程的TCP客户端(带参数和回调)
func (*Connection) SetProperty ¶
func (c *Connection) SetProperty(key string, value interface{})
SetProperty 设置链接属性
type IClient ¶
type IClient interface { SetOnConnStart(hookFunc func(netInterface.IConnection)) //设置连接开始事件 SetOnConnStop(hookFunc func(netInterface.IConnection)) //设置连接停止事件 SetOnReceive(hookFunc func(netInterface.IConnection, []byte)) //设置数据包上传完成事件(如果配置 config.HDataCache 为true(默认true)时方法运行完成后会回收,不可再另开协程处理]) SetHandleStrategy(h func(netInterface.IConnection, []byte) *netInterface.StrategyData) //设置处理策略,TCP和UDP表现不一样,tcp 只会在连接上第一包数据时调用,udp 会在每一包数上次都调用 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() //关闭 }
IClient 客户端