def handle(self): self.container = self.server._ThunderRPCInstance self.data = self.request.recv(2048) websock = websocket(self.request) decodedData = '' ws = False # Check to see if the data is coming over a websocket connection # (cloud interface) if (websock.isHandshakePending(self.data)): handshake = websock.handshake(self.data.decode()) self.request.sendall(handshake) d = self.request.recv(2) decodedData = websock.decode(d).strip() ws = True # Else, it could be coming from a peer (cloud server) else: decodedData = self.data.decode('UTF8').strip() # if there is data waiting to be processed then process it! if (decodedData != ''): decodedData = parseMessage(decodedData) if (ws): self.processWebsocketRequest(self.request, decodedData, websock) else: self.processTraditionalRequest(self.request, decodedData) return
def handle_conn(listen_sock): global ws global client_s cl, remote_addr = listen_sock.accept() cl.setblocking(False) client_s = cl websocket_helper.server_handshake(cl) ws = websocket(cl) cl.setsockopt(socket.SOL_SOCKET, 20, data_in) ws.write("connected to server")
def connect(self): try: if self.use_socketio: self.socket = SocketIO(SOCKETIO_URL, SOCKETIO_PATH) self.socket.connect() else: self.socket = websocket(WEBSOCKET_URL) self.events += Event(WEBSOCKET_CONNECTED) self.update_thread = threading.Thread(target=self.__run) self.stop = False self.update_thread.start() self.events += Event(UPDATE_THREAD_STARTED) except: self.events += Event(WEBSOCKET_DISCONNECTED, reconnect=True) return
def connect(self): request = urlopen("https://" + self.host + "/1") data = request.read() raw = data.split(b":") self.heartbeat_interval = int(raw[1]) if b"websocket" not in raw[3].split(b","): raise SocketIONotImplementedError("only websocket transport layer supported") self.id = raw[0].decode() self.connected = True url = "wss://" + self.host + "/1/websocket/" + self.id self.websocket = websocket(url) self.websocket.send(b"1::" + self.path.encode()) self.keepalive_thread = threading.Thread(target=self.__keepalive) self.keepalive_thread.setDaemon(True) self.keepalive_thread.start()
def connect(self): request = urlopen('https://' + self.host + '/1') data = request.read() raw = data.split(b':') self.heartbeat_interval = int(raw[1]) if b'websocket' not in raw[3].split(b','): raise SocketIONotImplementedError("only websocket transport layer supported") self.id = raw[0].decode() self.connected = True url = 'wss://'+self.host+'/1/websocket/'+self.id self.websocket = websocket(url) self.websocket.send(b'1::'+self.path.encode()) self.keepalive_thread = threading.Thread(target=self.__keepalive) self.keepalive_thread.setDaemon(True) self.keepalive_thread.start()
def handle_conn(listen_sock): cl, remote_addr = listen_sock.accept() print(""" First-time WebREPL connection has been received. WebREPL initial setup will now start over this connection. During setup, UART REPL will be non-responsive. After setup finishes, the board will be rebooted. In case of error during setup, current session will continue. If you receive this message unexpectedly, it may mean that your WebREPL connection is being hacked (power off board if unsure). """) websocket_helper.server_handshake(cl) ws = websocket(cl) ws.write("""\ Welcome to MicroPython WebREPL!\r \r This is the first time you connect to WebREPL, so please set a password\r to use for the following WebREPL sessions. Once you enter the password\r twice, your board will reboot with WebREPL running in active mode. On\r some boards, you may need to press reset button or reconnect power.\r \r """) while 1: passwd1 = getpass(ws, "New password: "******"Password too short\r\n") continue elif len(passwd1) > 9: ws.write("Password too long\r\n") continue passwd2 = getpass(ws, "Confirm password: "******"Passwords do not match\r\n") with open("port_config.py", "w") as f: f.write("WEBREPL_PASS = %r\n" % passwd1.decode("ascii")) ws.write("Password successfully set, restarting...\r\n") cl.close() time.sleep(2) import machine machine.reset()
def handle_conn(listen_sock): cl, remote_addr = listen_sock.accept() print(""" First-time WebREPL connection has been received. WebREPL initial setup will now start over this connection. During setup, UART REPL will be non-responsive. After setup finishes, the board will be rebooted. In case of error during setup, current session will continue. If you receive this message unexpectedly, it may mean that your WebREPL connection is being hacked (power off board if unsure). """) websocket_helper.server_handshake(cl) ws = websocket(cl) ws.write("""\ Welcome to MicroPython WebREPL!\r \r This is the first time you connect to WebREPL, so please set a password\r to use for the following WebREPL sessions. Once you enter the password\r twice, your board will reboot with WebREPL running in active mode. On\r some boards, you may need to press reset button or reconnect power.\r \r """) while 1: passwd1 = getpass(ws, "New password: "******"Password too short\r\n") continue passwd2 = getpass(ws, "Confirm password: "******"Passwords do not match\r\n") with open("port_config.py", "w") as f: f.write("WEBREPL_PASS = %r\n" % passwd1.decode("ascii")) ws.write("Password successfully set, restarting...\r\n") cl.close() time.sleep(2) import machine machine.reset()
("side",side), ("account",self.account)]) return simplejson.dumps(msg) def placeOrder(self,ticker,price,quantity,side): msg = self.make_order_msg(ticker,price,quantity,side) self.ws.send(msg) def delete(self): #Delete the WS self.logger.debug("Deleting the WS and threads") self.stopping.set() try: self.ws.close() if self.t_ws.isAlive(): self.t_ws.join() if self.export_to_db: if self.t_process.isAlive(): self.t_process.join() self.logger.debug("All threads and websocket closed") except: self.logger.exception("Error trying to close the WS and close the thread.") if __name__ == '__main__': from utils.createLogger import createLogger logger = createLogger() WS = websocket(user="******", password="******", entorno=1, account='REM898')