server

package
v1.7.27 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: MulanPSL-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 Clients

type Clients struct {
}

实现client

func (*Clients) OnClose

func (c *Clients) OnClose(cli *client.Client)

实现OnClose

func (*Clients) OnDataReport

func (c *Clients) OnDataReport(cli *client.Client, msg *aiot.Protocol)

实现OnDataReport

func (*Clients) OnDeviceControl

func (c *Clients) OnDeviceControl(cli *client.Client, msg *aiot.Protocol)

实现OnDeviceControl

func (*Clients) OnHeartBeat

func (c *Clients) OnHeartBeat(cli *client.Client, msg *aiot.Protocol)

实现OnHeartBeat

func (*Clients) OnRegister

func (c *Clients) OnRegister(cli *client.Client, msg *aiot.Protocol) bool

实现OnRegister

func (*Clients) OnRequest

func (c *Clients) OnRequest(cli *client.Client, msg *aiot.Protocol)

实现OnRequest

func (*Clients) OnResponse

func (c *Clients) OnResponse(cli *client.Client, msg *aiot.Protocol)

实现OnResponse

type Server

type Server struct {

	// 所有设备ID列表 key: masterId
	Devices map[string]*client.Client

	// logger
	Logger *zap.SugaredLogger
	// 守护进程间隔时间
	RestartTime time.Duration
	// 定时器
	Ticker *time.Ticker
	// contains filtered or unexported fields
}

服务端结构体

var Srv *Server

全局服务

func NewServer

func NewServer(addr string, serverId string, serverCallBack ServerCallBack, logger *zap.SugaredLogger, restartTime time.Duration) *Server

初始化服务

func (*Server) Handler

func (s *Server) Handler(clientConn net.Conn)

处理连接

func (*Server) IsOnline

func (s *Server) IsOnline(deviceId string) bool

是否注册

func (*Server) Lock

func (s *Server) Lock()

上锁

func (*Server) RegisterDevice

func (s *Server) RegisterDevice(cli *client.Client, msg *aiot.Protocol)

处理设备注册

func (*Server) Remove

func (s *Server) Remove(deviceId string) bool

删除离线设备

func (*Server) SetStatus

func (s *Server) SetStatus(state State)

设置连接状态

func (*Server) StartSrv

func (s *Server) StartSrv()

启动服务

func (*Server) SyncRequest

func (s *Server) SyncRequest(deviceId string, mstProto *aiot.MsgIdProto, req *aiot.BusinessReq, reply *aiot.BusinessReply) error

同步发送请求

func (*Server) UnLock

func (s *Server) UnLock()

解锁

type ServerCallBack

type ServerCallBack interface {
	// 收到心跳
	OnHeartBeat(c *client.Client, msg *aiot.Protocol)
	// 设备注册
	OnRegister(c *client.Client, msg *aiot.Protocol) bool
	// 收到请求
	OnRequest(c *client.Client, msg *aiot.Protocol)
	// 收到响应
	OnResponse(c *client.Client, msg *aiot.Protocol)
	// 数据上报
	OnDataReport(c *client.Client, msg *aiot.Protocol)
	// 设备控制
	OnDeviceControl(c *client.Client, msg *aiot.Protocol)
	// 通道关闭
	OnClose(c *client.Client)
}

回调接口

type State

type State int32

连接状态

const (
	// 初始化
	StateInit State = iota
	// 已注册
	StateStarted
	// 已关闭
	StateClosed
)

连接状态

Jump to

Keyboard shortcuts

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