From 25c6c83451d5d8634e839db09478dfdf524f57dd Mon Sep 17 00:00:00 2001 From: murmur Date: Sun, 19 Mar 2023 13:32:33 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=B6=85=E6=97=B6=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) 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) + "已断开连接。")