try: data = conn.recv(1048576).decode('ascii') if data is None: break print('recieved: ', data) hsh = hashlib.sha256(data.encode()).hexdigest()[:8] conn.sendall(hsh.encode('ascii')) try: j = json.loads(data) except json.decoder.JSONDecodeError: continue if j['command'] == Commands.SHUTDOWN: conn.close() break elif j['command'] == Commands.SET_POSITION: [x, y, z] = j['data'] cnc.set_position(x, y, z) elif j['command'] == Commands.SET_ORIGIN: pass elif j['command'] == Commands.LOAD_MSTP: mstp = j['data'] cnc.ct = mstp print("setting mstp data to ", cnc.ct) elif j['command'] == Commands.RUN_MSTP: cnc.run() except socket.error: break # Close the connection. conn.close()