删除无用函数

This commit is contained in:
murmur 2023-03-13 15:27:36 +08:00
parent 14aa2427d2
commit ac787a2fde

View File

@ -3,18 +3,17 @@
import socketserver import socketserver
import subprocess import subprocess
import pickle import pickle
offs = 0 # 偏移量
p = {}
# 保存终端信息ccid与地址对
# p={ccid=addr,}
# 缓存未能正常发送消息的客户端
pp = {}
# cache={}
from collections import defaultdict from collections import defaultdict
cache = defaultdict(list) cache = defaultdict(list)
offs = 0 # 偏移量
# 保存终端信息ccid=地址
p = {}
# 地址 ==ccid
pp = {}
def save_cache(dic): def save_cache(dic):
@ -92,15 +91,6 @@ def get_ccid(addr):
+--------+--------------+----------+----------+--------------+------------------------+--------+ +--------+--------------+----------+----------+--------------+------------------------+--------+
""" """
def send(fd, data):
try:
fd.send(data)
return 0
except:
return -1
def tt_hh(addr, data): def tt_hh(addr, data):
"""处理心跳""" """处理心跳"""
@ -119,15 +109,11 @@ def tt_hh(addr, data):
try: try:
# 按缓存先后顺序发送 # 按缓存先后顺序发送
addr.send(msgs[i]) addr.send(msgs[i])
# 成功则清空已发送成功的缓存数据
cache[ccid].pop(0) cache[ccid].pop(0)
print("",i+1,"包缓存数据发送完成。") print("",i+1,"包缓存数据发送完成。")
except: except:
# 异常时退出循环不用再尝试发送后续msgs # 异常时退出循环不用再尝试发送后续msgs
# 退出前清空已发送成功的缓存数据
# del方法会改变list大小
# while i:
# cache[ccid].pop(0)
# i = i - 1
print("",i+1,"包发送失败,停止尝试") print("",i+1,"包发送失败,停止尝试")
break break
if cache[ccid] == []: if cache[ccid] == []:
@ -187,14 +173,6 @@ def tt_trans(addr, data):
return 0 return 0
def err_handle(flag, addr):
"""错误处理\n
默认打印错误信息
1-非法连接关闭连接
"""
return 0
def data_split(data): def data_split(data):
# 按帧头分割长数据 # 按帧头分割长数据
@ -252,15 +230,12 @@ class MyServer(socketserver.BaseRequestHandler):
# print(type(conn),conn.fd) # print(type(conn),conn.fd)
while True: while True:
data = conn.recv(1000000) data = conn.recv(1024000)
# update_pairs(conn,data[7+offs:11+offs])
if not data: if not data:
break break
print( print(
"接收到新数据", self.client_address, ",长度", len(data), "\r\n", data.hex(" ") "接收到新数据", self.client_address, ",长度", len(data), "\r\n", data.hex(" ")
) )
# ack_msg = "got from "+ str(ip) + " to " + str(self.client_address) + data
# conn.send(data[:6])
if tt_decode(conn, data): if tt_decode(conn, data):
conn.close() conn.close()
print(self.client_address, "疑是非法连接,已切断。") print(self.client_address, "疑是非法连接,已切断。")