This commit is contained in:
邹宗楠
2026-05-12 17:28:46 +08:00
parent f2ce2db029
commit eaa27cbaa7
2 changed files with 14 additions and 33 deletions

View File

@@ -43,7 +43,7 @@ func ListenTcp() {
}
}()
if err := handleConn(c); err != nil {
if err = handleConn(c); err != nil {
c.Close()
Pool.Wait()
Pool.Stop()
@@ -61,11 +61,11 @@ func handleConn(c net.Conn) error {
for {
buffer, n, err := ConnRead(c)
remoteAddr := c.RemoteAddr().(*net.TCPAddr)
remoteIP := remoteAddr.IP.String() // 打印机IP
remotePort := remoteAddr.Port // 打印机端口
globals.SugarLogger.Debugf("remoteIP1: %s", remoteIP)
globals.SugarLogger.Debugf("remotePort1: %d", remotePort)
//remoteAddr := c.RemoteAddr().(*net.TCPAddr)
//remoteIP := remoteAddr.IP.String() // 打印机IP
//remotePort := remoteAddr.Port // 打印机端口
//globals.SugarLogger.Debugf("remoteIP1: %s", remoteIP)
//globals.SugarLogger.Debugf("remotePort1: %d", remotePort)
// 重连
if err != nil {
@@ -74,9 +74,6 @@ func handleConn(c net.Conn) error {
} else {
fmt.Println("ReadString err:", err)
}
printRemoteAddr22 := c.RemoteAddr().String()
printRemoteAddr22 = strings.Split(printRemoteAddr22, ":")[0]
globals.SugarLogger.Debugf("printRemoteAddr22: %s", printRemoteAddr22)
return err
}
@@ -98,12 +95,14 @@ func handleConn(c net.Conn) error {
}
globals.SugarLogger.Debugf("printNoData------: %s", printNo)
if value, have := TcpClientList.Load(printNo); !have {
t = NewTcpClient()
TcpClientList.Store(printNo, t)
} else {
t = value.(*TcpClient)
}
t = NewTcpClient()
TcpClientList.Delete(printNo)
TcpClientList.Store(printNo, t)
//if value, have := TcpClientList.Load(printNo); !have {
// TcpClientList.Store(printNo, t)
//} else {
// t = value.(*TcpClient)
//}
if heartbeat {
// 证明是心跳
Heartbeat(c, t, data, printNo, "")

View File

@@ -745,24 +745,6 @@ func doPrint(t *TcpClient, key string) (err error) {
dao.UpdateEntity(db, printMsg, "Status", "Comment")
return
}
// 链接已经关闭了
//if isClosed(c) {
// remoteAddr := c.RemoteAddr().(*net.TCPAddr)
// remoteIP := remoteAddr.IP.String() // 打印机IP
// remotePort := remoteAddr.Port // 打印机端口
// globals.SugarLogger.Debugf("remoteIP3: %s", remoteIP)
// globals.SugarLogger.Debugf("remotePort3: %d", remotePort)
//
// printRemoteAddr := c.RemoteAddr().String()
// printRemoteAddr = strings.Split(printRemoteAddr, ":")[0]
// globals.SugarLogger.Debugf("printRemoteAddr3: %s", printRemoteAddr)
//
// c = reconnectPrinter(c)
// if c != nil {
// t.setPrintConn(printMsg.PrintNo, c)
// }
//}
if _, err = c.Write(data); err != nil {
globals.SugarLogger.Debugf("handleTcpMessages err [%v]", err)
} else {