def add_request_socket(self, ws): sock = ClientSocket(ws) while not sock.is_closed(): data = sock.receive() if not data: sock.close() return data = self.command.parse(data) # Register if data and data.type == self.command_id.register and sock.get_id( ) is None: client_id = self.get_new_client_id() sock.set_id(client_id) if client_id: sock.send( self.command.build( dict(type=self.command_id.register, id=client_id)), True) else: sock.send( self.command.build(dict(type=self.command_id.error)), True) # Position Update elif data.type == self.command_id.update: self.update_player_position(sock.client_id, data.x, data.y)
def __init__(self): # 创建登录窗口 self.window = WindowLogin() # 创建聊天室窗口并隐藏 self.room = WindowChat() self.room.withdraw() # 服务器连接对象 self.conn = ClientSocket() # 存储响应处理函数 self.response_handle_functions = dict() # 处理服务器响应线程是否正在运行 self.is_running = True # 当前登录用户, 未登录之前为None self.username = None # 登录窗口按钮绑定点击处理方法 self.window.on_reset_button_click(lambda: self.clear_inputs()) self.window.on_login_button_click(lambda: self.send_login_data()) self.window.on_window_closed(lambda: self.exit()) # 聊天室窗口发送按钮绑定处理函数 self.room.on_send_button_click(lambda: self.send_chat_data()) self.room.on_window_closed(lambda: self.exit()) # 注册响应处理函数 self.register(RESPONSE_LOGIN_RESULT, lambda data: self.response_login_handle(data)) self.register(RESPONSE_CHAT, lambda data: self.response_chat_handle(data))
def test_marketdata(production): """client account information -> setup GDAX connection and print data""" p_ids = ['BTC-USD'] client_socket = ClientSocket(products=p_ids, auth=True, api_key=production['api_key'], api_secret=production['api_secret'], api_passphrase=production['api_pass'], channels=[ "level2", "heartbeat", { "name": "ticker", "product_ids": p_ids } ]) client_socket.start() print(client_socket.url, client_socket.products) try: while True: print("\nMessageCount =", "%i \n" % client_socket.msg_count) time.sleep(1) except KeyboardInterrupt: client_socket.close() if client_socket.error: sys.exit(1) else: sys.exit(0)
def __init__(self): #create a window for login self.window = WindowLogin() self.window.on_reset_button_click(self.clear_inputs) self.window.on_login_button_click(self.send_login_data) #self.window.on_window_close(self.exit) #create window for chat self.window_chat = WindowChat() #self.window_chat.on_window_close(self.exit) #hide chat window self.window_chat.withdraw() ###create socket for client self.conn = ClientSocket() self.response_handle_function = {} self.response_handle_function[ RESPONSE_LOGIN_RESULT] = self.response_login_handle self.response_handle_function[ RESPONSE_CHAT] = self.response_chat_handle self.window_chat.on_send_button_click(self.send_chat_data) #define a global variable to recode username online self.username = None #Whether the program is running self.isrunning = True
def add_state_socket(self, ws): sock = ClientSocket(ws) data = sock.receive() if data: data = self.command.parse(data) if data and data.type == self.command_id.register: sock.set_id(data.id) self.sockets.append(sock) else: sock.close()
def __init__(self): self.window = WindowLogin() self.room = WindowChat() self.room.withdraw() self.conn = ClientSocket() self.response_handle_functions = dict() self.is_running = True self.username = None self.register(RESPONSE_LOGIN_RESULT, lambda data: self.resonse_login_handle(data)) self.register(RESPONSE_CHAT, lambda data: self.reponse_chat_handle(data))
def authenticate(self): try: hashes = self.__generateParcialHashes() sock = ClientSocket(self.address,self.abi,hashes) except IOError as e: print(e.message) return -1 return sock.authenticate()
def __init__(self): #create login window: self.window = WindowLogin() self.window.on_reset_button_click(self.clear_inputs) self.window.on_login_button_click(self.send_login_data) #self.window.on_window_close(self.exit) #create chat window self.window_chat = WindowChat() #self.window_chat.on_window_close(self.exit) #hide the chat window self.window_chat.withdraw() #####create the client socket self.conn = ClientSocket() self.response_handle_function = {} self.response_handle_function[ RESPONSE_LOGIN_RESULT] = self.response_login_handle self.response_handle_function[ RESPONSE_CHAT] = self.response_chat_handle self.window_chat.on_send_button_click(self.send_chat_data) #define the global variable and record user name self.username = None #flag running program self.isrunning = True
def __init__(self): self.client = ClientSocket(self.host, self.port) self.port, addr = self.client.make_configuration() self.client.make_connection() self.observer = FSHandler(self.client.client_socket, self.host, self.port, addr)
clients = [] measurments = [] maxElements = 6 RELAY_COMM = True input_queue = multiprocessing.Queue() output_queue = multiprocessing.Queue() # IP_ADDR = '192.168.88.21' IP_ADDR = '192.168.1.10' video_cap = capture.SocketCapture(IP_ADDR) # video_cap = capture.FileCapture('py_opencv\\traseu1.mp4') comm_socket = ClientSocket(IP_ADDR, '8081') class IndexHandler(tornado.web.RequestHandler): def get(self): self.render('index.html') class StaticFileHandler(tornado.web.RequestHandler): def get(self): self.render('main.js') class WebSocketHandler(tornado.websocket.WebSocketHandler): def open(self): print 'new connection'
def __init__(self, server_address): ''' Create SendingQueue object ''' self.threads = [] # gevent provides a synchronized queue (locking is handled) self.queue = queue.Queue() self.socket_mgr = ClientSocket(server_address)
eName = PATH + "errorlog.txt" #the errorlog file try: fName = glob.glob(PATH + "*_data.csv")[0] print("Got " + fName) #print path to file print(fName[len(PATH):]) #print #file name except IndexError: #no file found print("Error") with open(eName, 'a') as f: print("Error no File Found for Upload: Exiting. Time: %i" % time.time(), file=f) f.close() exit(-1) #error con = ClientSocket() #start client socket with open(fName, 'r') as f: #open up the file in read mode data = f.read() con.sendName(fName[len(PATH):] ) #lets the server know which file is to be appended to con.send(data) #send the file f.close() #close the file if (con.rec() == '200'): #All clear condition print("Data Uploaded and received correctly") os.remove(fName) #remove the file from the client else: with open(eName, 'a') as f: print("Error Uploading: Keeping Data. Time: %i" % time.time(),
print("ERROR: {}".format(sentence["error"])) print("Say something: ") sentence = voice.listen_sentence_from_mic(voice.recognizer, voice.microphone) # Print sentence print("Your command was: {}".format(sentence["transcription"])) # Sending command via socket clientsocket.send_command(sentence["transcription"].encode()) except (KeyboardInterrupt, SystemExit): print("\n\nYou've finished this program. Thanks for using it. ;)") break if __name__ == "__main__": host = "192.168.0.24" port = 6002 # Creates an instance of the class that handles sockets client_socket = ClientSocket(host, port) # Creating thread to send instructions to the server voice_command_thread = threading.Thread(target=voice_command, args=(client_socket,)) # Creating thread to check the status sent by the server checking_thread = threading.Thread(target=client_socket.check_status) # Starting all threads voice_command_thread.start() checking_thread.start()
def add_client(self, addr, socket): new_client = ClientSocket(addr, socket, ENCODING, HEADERSIZE) self.client_sockets.append(new_client) self.server_broadcast(f"SERVER: {new_client.addr} has entered chat") print(f"[NEW CONNECTION] {new_client.addr} connected")