更新在线客户端显示算法

This commit is contained in:
murmur 2023-03-29 10:43:27 +08:00
parent 9115bfa8f2
commit 18ce9210cf

View File

@ -38,7 +38,7 @@ def s2wx(title="",description="", content=""):
"""通过自建msgpusher发送至微信 """通过自建msgpusher发送至微信
当前title值无效 当前title值无效
""" """
# return return
# 受API限制频繁发送会失败 # 受API限制频繁发送会失败
# 拟合并发送满3条已发送超时时间10s # 拟合并发送满3条已发送超时时间10s
@ -187,8 +187,10 @@ CCID:{ccid.decode()}
od= [] od= []
for i in pp: for i in pp:
p[pp[i]] = i 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)) # print('\r\n'.join(zd))
clents = ' \n'+'\r\n'.join(od) if len(od) else "" clents = ' \n'+'\r\n'.join(od) if len(od) else ""
print("在线终端已更新,数量",len(od),clents) print("在线终端已更新,数量",len(od),clents)
@ -405,8 +407,9 @@ class MyServer(socketserver.BaseRequestHandler):
def handle(self): # 回调 def handle(self): # 回调
add_timestamp() add_timestamp()
print("客户端", self.client_address, "已连接等待上报心跳注册ccid。") t=f"TCP客户端{str(self.client_address)}已连接等待上报心跳注册ccid。"
s2wx("天通消息","TCP客户端接入",f"TCP客户端{str(self.client_address)}已连接等待上报心跳注册ccid。") print(t)
s2wx("天通消息","TCP客户端接入",t)
conn = self.request conn = self.request
# print(type(conn),conn.fd) # print(type(conn),conn.fd)
@ -421,7 +424,7 @@ class MyServer(socketserver.BaseRequestHandler):
break break
add_timestamp() add_timestamp()
s2f.save2file(data) s2f.save2file(data)
t = f"接收到新数据,长度{len(data)}字节。" t = f"{str(self.client_address)}接收到新数据,长度{len(data)}字节。"
print(t) print(t)
s2wx("","",t) s2wx("","",t)
if tt_decode(conn, data): if tt_decode(conn, data):
@ -436,10 +439,11 @@ class MyServer(socketserver.BaseRequestHandler):
t = f"""终端下线了。{self.err} t = f"""终端下线了。{self.err}
CCID:{pp[self.request].decode()} CCID:{pp[self.request].decode()}
地址:{str(self.client_address)}""" 地址:{str(self.client_address)}"""
update_pairs(self.request,get_ccid(self.request),1)
print(t) print(t)
s2wx("","天通终端下线了",t) s2wx("","天通终端下线了",t)
# print("终端",self.client_address,"下线了。",self.err) # 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: else:
t= f"TCP客户端{str(self.client_address)}已断开连接。{self.err}" t= f"TCP客户端{str(self.client_address)}已断开连接。{self.err}"
print(t) print(t)