其中一方断线后,通知另一方断开连接
This commit is contained in:
18
target.py
18
target.py
@@ -14,12 +14,14 @@ import prot_codec as pc
|
||||
# device:
|
||||
# server
|
||||
# client
|
||||
# proxy
|
||||
# 定义操作类型
|
||||
# option:
|
||||
# connect
|
||||
# disconnect
|
||||
# data
|
||||
# login
|
||||
# close
|
||||
|
||||
|
||||
_tcp_server=None
|
||||
@@ -53,5 +55,21 @@ class tcp_target(object):
|
||||
else:
|
||||
if(_tcp_client is not None):
|
||||
_tcp_client.send(recv_data)
|
||||
# 只要有一个断了所有的都断开
|
||||
def close(self):
|
||||
cmd={'device':'proxy','option':'close'}
|
||||
data=pc.encode(json.dumps(cmd).encode('utf-8'),b'default')
|
||||
# 这里有可能连接已经断开,无法发送
|
||||
if(_tcp_client is not None):
|
||||
try:
|
||||
_tcp_client.send(data)
|
||||
except Exception as e:
|
||||
print("target_close:",str(e))
|
||||
if(_tcp_server is not None):
|
||||
try:
|
||||
_tcp_server.send(data)
|
||||
except Exception as e:
|
||||
print("target_close:",str(e))
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user