增加超时提示。

This commit is contained in:
murmur 2023-03-19 13:32:33 +08:00
parent 76b9167423
commit 25c6c83451

View File

@ -7,6 +7,7 @@ from collections import defaultdict
import datetime import datetime
import time import time
import requests import requests
import socket
# import json # import json
@ -34,7 +35,7 @@ def s2wx(title,description, content):
"""通过自建msgpusher发送至微信 """通过自建msgpusher发送至微信
当前title值无效 当前title值无效
""" """
# pass # return
# GET 方式 # GET 方式
# res = requests.get(f"{SERVER}/push/{USERNAME}?title={title}" # res = requests.get(f"{SERVER}/push/{USERNAME}?title={title}"
# f"&description={description}&content={content}&token={TOKEN}") # f"&description={description}&content={content}&token={TOKEN}")
@ -302,17 +303,21 @@ def tt_decode(addr, data):
class MyServer(socketserver.BaseRequestHandler): class MyServer(socketserver.BaseRequestHandler):
def setup(self): def setup(self):
self.server.timeout=3 self.request.settimeout(60*2)
def handle(self): # 回调 def handle(self): # 回调
add_timestamp() add_timestamp()
print("客户端", self.client_address, "已连接等待上报心跳注册ccid。") print("客户端", self.client_address, "已连接等待上报心跳注册ccid。")
s2wx("天通消息","TCP客户端已连",str(self.client_address) + "已连接等待上报心跳注册ccid。") s2wx("天通消息","TCP客户端",str(self.client_address) + "已连接等待上报心跳注册ccid。")
conn = self.request conn = self.request
# print(type(conn),conn.fd) # print(type(conn),conn.fd)
while True: while True:
try:
data = conn.recv(1024000) data = conn.recv(1024000)
except socket.timeout:
print(self.client_address, "超时。")
break
if not data: if not data:
break break
add_timestamp() add_timestamp()
@ -336,7 +341,7 @@ CCID:{get_ccid(self.request)}
print("终端",self.client_address,"下线了。") print("终端",self.client_address,"下线了。")
update_pairs(self.request,get_ccid(self.request),1) update_pairs(self.request,get_ccid(self.request),1)
else: else:
print("客户端",self.client_address,"已断开连接") print("客户端",self.client_address,"已断开")
s2wx("天通消息","TCP客户端断开",str(self.client_address) + "已断开连接。") s2wx("天通消息","TCP客户端断开",str(self.client_address) + "已断开连接。")