| | |
| | | "bufio" |
| | | "encoding/binary" |
| | | "encoding/json" |
| | | "errors" |
| | | uuid "github.com/satori/go.uuid" |
| | | "go.uber.org/zap" |
| | | "io" |
| | |
| | | DefaultHeartbeatInterval = 15 * time.Second |
| | | // 读取数据超时时间 |
| | | DefaultReaderTimeOut = 60 * time.Second |
| | | // 连接尝试间隔 |
| | | DefaultNetRetry = 10 * time.Second |
| | | ) |
| | | |
| | | // 连接状态 |
| | |
| | | // 已断开 |
| | | StateDisconnected |
| | | ) |
| | | |
| | | var syncReq map[string]chan *aiot.Protocol |
| | | |
| | | // 连接状态 |
| | | type State int32 |
| | |
| | | } |
| | | |
| | | // 发送消息 |
| | | c.WriteBody(body) |
| | | _ = c.WriteBody(body) |
| | | return body, nil |
| | | } |
| | | |
| | |
| | | c.Logger.Error("Write Body Error:", err) |
| | | } |
| | | }() |
| | | |
| | | if c.IsClosed() { |
| | | errMsg := "Can not write msg into closed chain" |
| | | c.Logger.Warn(errMsg, zap.Any("msg",body)) |
| | | return errors.New(errMsg) |
| | | } |
| | | body.Receiver = aiot.RECEIVER_TO_SAAS |
| | | msgData, err := json.Marshal(body) |
| | | if err != nil { |
| | |
| | | defer c.closeLock.Unlock() |
| | | // 关闭通道 |
| | | if !c.IsClosed() { |
| | | c.Conn.Close() |
| | | _ = c.Conn.Close() |
| | | if c.IsConnected() { |
| | | c.clientCallback.OnClose(c) |
| | | } |