def send(self,data): try: data_s = package.pack(data) self.client.send(data_s) data_c = self.client.recv(2048) return package.unpack(data_c) except socket.error as e: print(e)
def connect(self): try: self.client.connect(self.addr) data_c = package.unpack(self.client.recv(2048)) return data_c except: pass
def threaded_client(cliente_local, player): #data_s = package.pack(make_pos(pos[player])) data_s = package.pack(keys_players[player]) cliente_local.send(data_s) reply = "" while 1: try: data_c = package.unpack(cliente_local.recv(2048)) #data = read_pos(data_c) #pos[player] = data data = data_c keys_players[player] = data if not data: print("Disconected") break else: if player == 1: #reply = pos[0] reply = keys_players[0] else: #reply = pos[1] reply = keys_players[1] #data_s = package.pack(make_pos(reply)) data_s = package.pack(reply) cliente_local.send(data_s) except socket.error as e: print(e) break print("Lost Connection ") cliente_local.close()