Documentation ¶
Index ¶
- Constants
- func GetMsgProto(msgId string) *aiot.MsgIdProto
- type Client
- func (c *Client) BusinessRequest(senderId string, msgProto *aiot.MsgIdProto, data []byte) error
- func (c *Client) Close()
- func (c *Client) GetDeviceId() string
- func (c *Client) GetState() State
- func (c *Client) InitClient()
- func (c *Client) IsClosed() bool
- func (c *Client) IsConnected() bool
- func (c *Client) SetCallBack(callBack ClientCallBack)
- func (c *Client) SetDeviceId(deviceId string)
- func (c *Client) SetRWBuf()
- func (c *Client) SetState(state State)
- func (c *Client) StartSrv(step time.Duration)
- func (c *Client) Wait()
- func (c *Client) WriteBody(body *aiot.Protocol) error
- type ClientCallBack
- type State
Constants ¶
View Source
const ( // 最大消息长度 DefaultBufferSize = 512 * 1024 // 心跳间隔 DefaultHeartbeatInterval = 15 * time.Second // 读取数据超时时间 DefaultReaderTimeOut = 60 * time.Second )
消息及时长
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct { net.Conn // 消息读取buffer Reader *bufio.Reader // 消息写入buffer Writer *bufio.Writer // logger Logger *zap.SugaredLogger // 守护进程间隔时间 RestartTime time.Duration // 定时器 Ticker *time.Ticker // contains filtered or unexported fields }
客户端连接结构体
func NewClient ¶
func NewClient(addr string, clientId string, deviceRegister *aiot.DeviceRegister, callBack ClientCallBack, logger *zap.SugaredLogger, restartTime time.Duration) *Client
初始化客户端
func (*Client) BusinessRequest ¶
发送业务包请求
type ClientCallBack ¶
type ClientCallBack interface { // 心跳响应 OnHeartBeat(cli *Client, msg *aiot.Protocol) // 设备注册响应 OnRegister(cli *Client, msg *aiot.Protocol) bool // 收到响应回调方法 OnResponse(cli *Client, msg *aiot.Protocol) // 收到请求 OnRequest(cli *Client, msg *aiot.Protocol) // 设备控制 OnDeviceControl(cli *Client, msg *aiot.Protocol) // 数据下发 OnDataReport(cli *Client, msg *aiot.Protocol) // 关闭连接回调方法 OnClose(cli *Client) }
回调接口
Click to show internal directories.
Click to hide internal directories.