更新缓存重发函数逻辑
This commit is contained in:
parent
953975dd3b
commit
f5e5357547
19
server.py
19
server.py
@ -110,19 +110,28 @@ def tt_hh(addr, data):
|
||||
# 从缓存中匹配数据并重发
|
||||
# 仅有新终端上线时才重发
|
||||
if ccid in cache:
|
||||
msgs = cache[ccid]
|
||||
msgs = cache[ccid][:] # 浅拷贝
|
||||
sccid=msgs[0][7 + offs : 11 + offs].decode()
|
||||
print("有",len(msgs),"包缓存数据待发,源ccid:",sccid)
|
||||
for i in range(len(msgs)):
|
||||
try:
|
||||
# 按缓存先后顺序发送
|
||||
addr.send(msgs[i])
|
||||
cache[ccid].pop(0)
|
||||
print("第",i+1,"包缓存数据发送完成。")
|
||||
except:
|
||||
# 异常时退出循环,不用再尝试发送后续msgs
|
||||
# 退出前清空已发送成功的缓存数据
|
||||
# del方法会改变list大小
|
||||
while i:
|
||||
cache[ccid].pop(0)
|
||||
i = i - 1
|
||||
# while i:
|
||||
# cache[ccid].pop(0)
|
||||
# i = i - 1
|
||||
print("第",i+1,"包发送失败,停止尝试")
|
||||
break
|
||||
if cache[ccid] == []:
|
||||
print("缓存数据发送完成,源ccid:",sccid)
|
||||
del cache[ccid]
|
||||
save_cache(cache)
|
||||
|
||||
return 0
|
||||
|
||||
@ -206,7 +215,7 @@ def tt_decode(addr, data):
|
||||
|
||||
class MyServer(socketserver.BaseRequestHandler):
|
||||
def handle(self): # 回调
|
||||
print("终端已上线:", self.client_address)
|
||||
print("终端", self.client_address,"已上线,等待上报心跳。")
|
||||
conn = self.request
|
||||
# print(type(conn),conn.fd)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user