netClient

package
v1.7.7 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2021 License: Apache-2.0 Imports: 13 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 {
	// 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) Close added in v1.4.1

func (c *Client) Close()

关闭

func (*Client) Connect

func (c *Client) Connect() (bool, error)

连接到服务

func (*Client) GetConn

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

获取客户端连接

func (*Client) SendData added in v1.5.2

func (c *Client) SendData(data []byte, cmdCode string) error

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

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:等待处理】
}

配置

func DefaultConfig added in v1.3.0

func DefaultConfig(network, Host string) *Config

默认配置

func NewConfig added in v1.5.0

func NewConfig(network, Host, certFile, keyFile string, isTls bool) *Config

默认配置

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) GetConnId

func (c *Connection) GetConnId() uint64

获取客户端ID

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) GetReceiver

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

获取分包器

func (*Connection) GetRemoteAddr

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

获取远程客户端地址信息

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) OnCompleted

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

数据上传处理

func (*Connection) OnReceive added in v1.6.1

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

数据分包完成

func (*Connection) RemoveProperty

func (c *Connection) RemoveProperty(key string)

移除链接属性

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{})

设置链接属性

func (*Connection) Start

func (c *Connection) Start()

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

func (*Connection) Stop

func (c *Connection) Stop()

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

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()                            //关闭
}

客户端

func NewClient

func NewClient(config *Config) IClient

创建一个客户端对象

Jump to

Keyboard shortcuts

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