删除无用函数
This commit is contained in:
parent
14aa2427d2
commit
ac787a2fde
45
server.py
45
server.py
@ -3,18 +3,17 @@
|
||||
import socketserver
|
||||
import subprocess
|
||||
import pickle
|
||||
|
||||
|
||||
offs = 0 # 偏移量
|
||||
p = {}
|
||||
# 保存终端信息,ccid与地址对
|
||||
# p={ccid=addr,}
|
||||
# 缓存未能正常发送消息的客户端
|
||||
pp = {}
|
||||
# cache={}
|
||||
from collections import defaultdict
|
||||
|
||||
cache = defaultdict(list)
|
||||
offs = 0 # 偏移量
|
||||
|
||||
# 保存终端信息,ccid=地址
|
||||
p = {}
|
||||
# 地址 ==ccid
|
||||
pp = {}
|
||||
|
||||
|
||||
|
||||
|
||||
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):
|
||||
"""处理心跳"""
|
||||
|
||||
@ -119,15 +109,11 @@ def tt_hh(addr, data):
|
||||
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
|
||||
print("第",i+1,"包发送失败,停止尝试")
|
||||
break
|
||||
if cache[ccid] == []:
|
||||
@ -187,14 +173,6 @@ def tt_trans(addr, data):
|
||||
return 0
|
||||
|
||||
|
||||
def err_handle(flag, addr):
|
||||
"""错误处理\n
|
||||
默认打印错误信息
|
||||
1-非法连接,关闭连接
|
||||
"""
|
||||
|
||||
return 0
|
||||
|
||||
def data_split(data):
|
||||
# 按帧头分割长数据
|
||||
|
||||
@ -252,15 +230,12 @@ class MyServer(socketserver.BaseRequestHandler):
|
||||
# print(type(conn),conn.fd)
|
||||
|
||||
while True:
|
||||
data = conn.recv(1000000)
|
||||
# update_pairs(conn,data[7+offs:11+offs])
|
||||
data = conn.recv(1024000)
|
||||
if not data:
|
||||
break
|
||||
print(
|
||||
"接收到新数据", 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):
|
||||
conn.close()
|
||||
print(self.client_address, "疑是非法连接,已切断。")
|
||||
|
Loading…
Reference in New Issue
Block a user