From 18ce9210cfb16a559de7158fde6bf55b12c09686 Mon Sep 17 00:00:00 2001 From: murmur Date: Wed, 29 Mar 2023 10:43:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E5=9C=A8=E7=BA=BF=E5=AE=A2?= =?UTF-8?q?=E6=88=B7=E7=AB=AF=E6=98=BE=E7=A4=BA=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/server.py b/server.py index 61ce85e..07a5943 100755 --- a/server.py +++ b/server.py @@ -38,7 +38,7 @@ def s2wx(title="",description="", content=""): """通过自建msgpusher发送至微信 当前title值无效 """ - # return + return # 受API限制,频繁发送会失败 # 拟合并发送,满3条已发送,超时时间10s @@ -187,8 +187,10 @@ CCID:{ccid.decode()} od= [] for i in pp: p[pp[i]] = i - # print(pp[i],"<--->",i) - od.append(f"{pp[i].decode()}<--->{i.getpeername()}") + # od.append(f"{pp[i].decode()}<--->{i.getpeername()}") + # 可能客户端未断开,导致多个连接指向相同的ccid,故需更新后再遍历打印 + for i in p: + od.append(f"{i}<--->{p[i].getpeername()}") # print('\r\n'.join(zd)) clents = ' \n'+'\r\n'.join(od) if len(od) else "" print("在线终端已更新,数量",len(od),clents) @@ -405,8 +407,9 @@ class MyServer(socketserver.BaseRequestHandler): def handle(self): # 回调 add_timestamp() - print("客户端", self.client_address, "已连接,等待上报心跳注册ccid。") - s2wx("天通消息","TCP客户端接入",f"TCP客户端{str(self.client_address)}已连接,等待上报心跳注册ccid。") + t=f"TCP客户端{str(self.client_address)}已连接,等待上报心跳注册ccid。" + print(t) + s2wx("天通消息","TCP客户端接入",t) conn = self.request # print(type(conn),conn.fd) @@ -421,7 +424,7 @@ class MyServer(socketserver.BaseRequestHandler): break add_timestamp() s2f.save2file(data) - t = f"接收到新数据,长度{len(data)}字节。" + t = f"从{str(self.client_address)}接收到新数据,长度{len(data)}字节。" print(t) s2wx("","",t) if tt_decode(conn, data): @@ -436,10 +439,11 @@ class MyServer(socketserver.BaseRequestHandler): t = f"""终端下线了。{self.err} CCID:{pp[self.request].decode()} 地址:{str(self.client_address)}""" + update_pairs(self.request,get_ccid(self.request),1) print(t) s2wx("","天通终端下线了",t) # print("终端",self.client_address,"下线了。",self.err) - update_pairs(self.request,get_ccid(self.request),1) + # update_pairs(self.request,get_ccid(self.request),1) else: t= f"TCP客户端{str(self.client_address)}已断开连接。{self.err}" print(t)