mirror of
https://github.com/DJ2LS/FreeDATA
synced 2024-05-14 08:04:33 +00:00
better error handling
This commit is contained in:
parent
69b0ba4c5c
commit
3575a51398
1 changed files with 153 additions and 148 deletions
11
sock.py
11
sock.py
|
@ -21,10 +21,12 @@ import helpers
|
||||||
class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
|
|
||||||
def handle(self):
|
def handle(self):
|
||||||
|
print("Client connected...")
|
||||||
|
|
||||||
# loop through socket buffer until timeout is reached. then close buffer
|
# loop through socket buffer until timeout is reached. then close buffer
|
||||||
socketTimeout = time.time() + 3
|
socketTimeout = time.time() + 3
|
||||||
while socketTimeout > time.time():
|
while socketTimeout > time.time():
|
||||||
|
|
||||||
time.sleep(0.01)
|
time.sleep(0.01)
|
||||||
encoding = 'utf-8'
|
encoding = 'utf-8'
|
||||||
#data = str(self.request.recv(1024), 'utf-8')
|
#data = str(self.request.recv(1024), 'utf-8')
|
||||||
|
@ -50,7 +52,7 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
received_json = json.loads(data)
|
received_json = json.loads(data)
|
||||||
print(received_json)
|
print(received_json)
|
||||||
except:
|
except:
|
||||||
received_json = bytes()
|
received_json = ''
|
||||||
|
|
||||||
|
|
||||||
# GET COMMANDS
|
# GET COMMANDS
|
||||||
|
@ -67,7 +69,7 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
# "data" : "..."
|
# "data" : "..."
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
# SOCKETTEST ---------------------------------------------------
|
# SOCKETTEST ---------------------------------------------------
|
||||||
#if data == 'SOCKETTEST':
|
#if data == 'SOCKETTEST':
|
||||||
if received_json["command"] == "SOCKETTEST":
|
if received_json["command"] == "SOCKETTEST":
|
||||||
|
@ -231,7 +233,10 @@ class CMDTCPRequestHandler(socketserver.BaseRequestHandler):
|
||||||
if received_json["type"] == 'SET' and received_json["command"] == 'DEL_RX_BUFFER':
|
if received_json["type"] == 'SET' and received_json["command"] == 'DEL_RX_BUFFER':
|
||||||
static.RX_BUFFER = []
|
static.RX_BUFFER = []
|
||||||
|
|
||||||
print("sock timeout...")
|
#exception, if JSON cant be decoded
|
||||||
|
except:
|
||||||
|
print("Wrong command")
|
||||||
|
print("Client disconnected...")
|
||||||
|
|
||||||
def start_cmd_socket():
|
def start_cmd_socket():
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue