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) GetRemoteAddr() net.Addr
- func (c *Connection) GetRepInfo() (count, byteSize, errCount uint64)
- 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) SetCreateReceiver ¶
func (c *Client) SetCreateReceiver(hookFunc func(netInterface.IConnection, []byte) []netInterface.IReceiver)
SetCreateReceiver 设置创建分包策略方法
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 //下行超时时间(秒) CertFile string //server.crt 文件路径:TCP支持Tls KeyFile string //server.key 文件路径:TCP支持Tls IsTls bool //是否tls连接 OverflowDiscard bool //接收,处理,回复溢出是否丢弃【true:丢弃,false:等待处理】 }
Config 配置
func DefaultConfig ¶ added in v1.3.0
DefaultConfig 默认配置
type Connection ¶
type Connection struct {
// contains filtered or unexported fields
}
Connection 连接结构体
func NewConntion ¶
func NewConntion(client *Client, conn net.Conn, config *Config) *Connection
NewConntion 创建连接的方法
func (*Connection) CallLogHandle ¶ added in v1.2.0
func (c *Connection) CallLogHandle(level netInterface.ErrLevel, msgAry ...interface{})
CallLogHandle 调用异常处理
func (*Connection) CreateReceiver ¶
func (c *Connection) CreateReceiver(data []byte) []netInterface.IReceiver
CreateReceiver 创建分包器
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) 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)) //设置数据包上传完成事件 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() //关闭 }
IClient 客户端