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