修改链接数据读取方式

This commit is contained in:
邹宗楠
2023-06-05 14:38:15 +08:00
parent 078ca7e9b2
commit 71234f6b48

View File

@@ -10,6 +10,7 @@ import (
"git.rosy.net.cn/jx-callback/business/model/dao"
"git.rosy.net.cn/jx-callback/globals"
"io"
"io/ioutil"
"net"
"strings"
"time"
@@ -84,9 +85,11 @@ func handleConn(c net.Conn, t *TcpClient) error {
for {
var (
printNo string //打印机编号
buffer = make([]byte, 1024)
//buffer = make([]byte, 1024)
)
n, err := c.Read(buffer)
//n, err := c.Read(buffer)
//io.ReadFull(c, buffer)
buffer, err := ioutil.ReadAll(c)
if err != nil {
if err == io.EOF {
fmt.Println("connection close")
@@ -98,12 +101,12 @@ func handleConn(c net.Conn, t *TcpClient) error {
}
//看是心跳还是打印回调
data := hex.EncodeToString(buffer[:n])
if strings.Contains(string(buffer[0:n]), "print_no_clear") { // 清理缓存
data := hex.EncodeToString(buffer[:len(buffer)])
if strings.Contains(string(buffer[0:len(buffer)]), "print_no_clear") { // 清理缓存
param := struct {
PrintNoClear json.Number `json:"print_no_clear"`
}{}
if err := json.Unmarshal(buffer[0:n], &param); err != nil {
if err := json.Unmarshal(buffer[0:len(buffer)], &param); err != nil {
c.Write([]byte(err.Error()))
return err
}