improve client isConnected method

This commit is contained in:
Bastian Schroll 2019-10-23 08:59:19 +02:00
parent 361afe2ff1
commit 3cd5a59bb5
2 changed files with 2 additions and 11 deletions

View file

@ -105,13 +105,7 @@ class TCPClient:
@property
def isConnected(self):
"""!Property of client connected state"""
try:
aliveMsg = "<alive>"
header = str(len(aliveMsg)).ljust(HEADERSIZE)
self._sock.sendall(bytes(header + aliveMsg, "utf-8"))
_, write, _ = select.select([], [self._sock], [], 0.1)
if write:
return True
except socket.error as e:
if e.errno is 32: # broken pipe - no one will read from this pipe anymore
return False
logging.error(e)
return False

View file

@ -55,9 +55,6 @@ class _ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):
length = int(header.decode("utf-8").strip())
data = self.request.recv(length).decode("utf-8")
if data == "<alive>":
continue
logging.debug("%s recv %d bytes:\n%s", req_name, length, pformat(data))
# add a new entry and the decoded data dict as an string in utf-8 and an timestamp