From 02a4d37cc31f3f49357fbecac400dfc124bcb858 Mon Sep 17 00:00:00 2001 From: murmur Date: Tue, 21 Mar 2023 15:14:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E9=83=A8=E5=88=86=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E7=AE=97=E6=B3=95=20=E4=B8=B4=E6=97=B6=E5=85=B3?= =?UTF-8?q?=E9=97=AD=E4=B8=BB=E5=8A=A8=E5=88=87=E6=96=AD=E5=AE=A2=E6=88=B7?= =?UTF-8?q?=E7=AB=AF=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.py | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/server.py b/server.py index fccb3fe..a822c2d 100755 --- a/server.py +++ b/server.py @@ -100,18 +100,21 @@ def update_pairs(addr, ccid, clear=0): ccid:终端号 clear:清空掉线终端""" - if ccid and not clear: + if not clear: # 添加或更新客户端 + pp[addr] = ccid + p.clear + if ccid not in p: t = f"""*信息:* 天通终端上线。 CCID:{ccid.decode()} 地址:{str(addr.getpeername())} """ + print(t) s2wx("","天通终端上线",t) # p[ccid] = addr - pp[addr] = ccid - p.clear + else: del p[ccid] del pp[addr] @@ -343,23 +346,25 @@ class MyServer(socketserver.BaseRequestHandler): ) s2wx("","",f"接收到新数据,长度{len(data)}字节。") if tt_decode(conn, data): - conn.close() - print(self.client_address, "疑是非法连接,已切断。") - break + self.err= "切断。" + print(self.client_address, "疑是非法连接") + # conn.close() + # break def finish(self): if self.request in pp: t = f"""终端下线了。{self.err} CCID:{pp[self.request].decode()} -地址:{str(self.client_address)} - """ +地址:{str(self.client_address)}""" + print(t) s2wx("","天通终端下线了",t) - print("终端",self.client_address,"下线了。") + # print("终端",self.client_address,"下线了。",self.err) update_pairs(self.request,get_ccid(self.request),1) else: - print("客户端",self.client_address,"已断开。") - s2wx("天通消息","TCP客户端断开",f"TCP客户端{str(self.client_address)}已断开连接。{self.err}") + t= f"TCP客户端{str(self.client_address)}已断开连接。{self.err}" + print(t) + s2wx("天通消息","TCP客户端断开",t)