From e17194b628bd4837a5cecb71da60c09fef45a152 Mon Sep 17 00:00:00 2001 From: murmur Date: Mon, 3 Apr 2023 10:08:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0save2file=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- s2f.py | 11 ++++++++--- server.py | 7 ++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/s2f.py b/s2f.py index 1c3c898..66181d0 100644 --- a/s2f.py +++ b/s2f.py @@ -1,3 +1,8 @@ - -def save2file(data): - pass \ No newline at end of file +import datetime +def save2file(data,isR=1): + # pass + t= datetime.datetime.now() + l=f"{'[R]' if isR else '[T]'} - {str(t)} --- {data.hex(' ')}\n" + f=open('./rxlog.txt','a') + f.write(l) + f.close \ No newline at end of file diff --git a/server.py b/server.py index 1d29cfa..b93cb1f 100755 --- a/server.py +++ b/server.py @@ -341,6 +341,7 @@ def tt_trans(addr, data): try: add_timestamp() taddr.send(msg) + s2f.save2file(msg,0) print("数据发送成功。", sccid, "-->", tccid) s2wx("","",f"匹配到在线终端, 数据发送成功。 \n{sccid.decode()} ---> {tccid.decode()}") except Exception: @@ -405,6 +406,7 @@ class MyServer(socketserver.BaseRequestHandler): def setup(self): self.request.settimeout(60*10) self.err = " " + self.recDataBuff=[] def handle(self): # 回调 add_timestamp() @@ -424,11 +426,14 @@ class MyServer(socketserver.BaseRequestHandler): if not data: break add_timestamp() + self.recDataBuff.extend(data) s2f.save2file(data) t = f"从{str(self.client_address)}<->[{get_ccid(conn).decode() if get_ccid(conn) else 'None'}]接收到新数据,长度{len(data)}字节。" print(t) - print(data) + print(data.hex(" ")) s2wx("","",t) + print("--",len(self.recDataBuff)) + print(self.recDataBuff[:]) if tt_decode(conn, data): self.err= "切断。" print(self.client_address, "疑是非法连接")