def threaded_client(conn): try: while True: data = conn.recv() data = data[0] * 256 + data[1] data = BP.decode(data) print('Received data:', data) send_command(conn, data) except RuntimeError as e: print(e) #except Exception as e: #print('Exception caught') #print(e) finally: conn.close()