增加重连

This commit is contained in:
qiyunfanbo126.com 2025-01-22 16:09:03 +08:00
parent 92ebac31b9
commit 705fa97062
2 changed files with 12 additions and 13 deletions

View File

@ -145,7 +145,8 @@ func (t *TcpHelper) watch(conn net.Conn) {
} else { } else {
atomic.StoreInt32(t.Full, 1) atomic.StoreInt32(t.Full, 1)
utils.Log(nil, "连接关闭", err) utils.Log(nil, "连接关闭", err)
//t.reconnect(config.GetConf().OrderPort) t.client.Close()
t.reconnect(config.GetConf().OrderPort)
} }
} }
time.Sleep(1 * time.Second) time.Sleep(1 * time.Second)

View File

@ -41,7 +41,7 @@ func handleConnection(conn net.Conn) {
} }
// 将读取到的字符串转换为字节切片 // 将读取到的字符串转换为字节切片
buf = []byte(line) buf = []byte(line)
if err == nil && len(buf) > 1 { if err == nil && len(buf) > 2 {
if atomic.LoadInt32(workSingleNum) >= int32(maxNum) { if atomic.LoadInt32(workSingleNum) >= int32(maxNum) {
if atomic.LoadInt32(busySingle) == 0 { if atomic.LoadInt32(busySingle) == 0 {
fmt.Println("繁忙") fmt.Println("繁忙")
@ -51,19 +51,17 @@ func handleConnection(conn net.Conn) {
} }
} else { } else {
if len(buf) > 2 { var data map[string]interface{}
var data map[string]interface{} json.Unmarshal(buf, &data)
json.Unmarshal(buf, &data) fmt.Println("收到", *workSingleNum, maxNum, string(buf))
fmt.Println("收到", *workSingleNum, maxNum, string(buf)) conn.Write([]byte(data["serial_number"].(string) + "\n"))
conn.Write([]byte(data["serial_number"].(string) + "\n")) go handLogacal(conn, buf)
go handLogacal(conn, buf) atomic.AddInt32(workSingleNum, 1)
atomic.AddInt32(workSingleNum, 1) conn.Write([]byte("2\n"))
} else {
conn.Write([]byte("2\n"))
}
} }
} else {
conn.Write([]byte("6\n"))
} }
} }