// Copyright 2019 autocareai.com. All rights reserved. // Use of this source code is governed by autocareai.com. package tcp_packet import ( "context" dust "dust-monitor/handler/v1" "dust-monitor/util" "fmt" "net" ) func monitorDataHandel(src []byte) (err error) { // 解析数据帧 frame := util.DustFrameParse(src) err = dust.DustDataHandle(context.Background(), &frame) return err } func HandleSocketClient(conn net.Conn) { // 处理完后关闭连接 defer conn.Close() request := make([]byte, 1024) var gleft, result []byte var isComplete bool for { read_len, err := conn.Read(request) fmt.Printf("read read:%v,%v,%s\n", read_len, err, request[:read_len]) if err != nil { break } gleft = append(gleft, request[:read_len]...) for { result, gleft, isComplete, err = util.DustParse(gleft[:]) if err != nil { return } // 包没有读完继续读取数据包 if isComplete == false { break } fmt.Printf("complete:%s\n", result) // 处理数据 monitorDataHandel(result) } } }