添加save2file实现
This commit is contained in:
parent
39c35f06a0
commit
e17194b628
11
s2f.py
11
s2f.py
@ -1,3 +1,8 @@
|
||||
|
||||
def save2file(data):
|
||||
pass
|
||||
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
|
@ -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, "疑是非法连接")
|
||||
|
Loading…
Reference in New Issue
Block a user