Ejemplo n.º 1
0
def threaded_client(conn, player):

    data_s = package.pack(keys_players[player])
    conn.send(data_s)
    reply = ""

    while 1:
        try:

            try:
                data_c = package.unpack(conn.recv(2048))
            except:
                break

            keys_players[player] = data_c

            if not data_c:
                print("Disconected")
                break

            else:
                if player == 1:
                    reply = keys_players[0]
                else:
                    reply = keys_players[1]

            data_s = package.pack(reply)
            conn.send(data_s)

        except socket.error as e:
            print(e)
            break

    print("Lost Connection ")
    conn.close()
Ejemplo n.º 2
0
    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)
Ejemplo n.º 3
0
    def connect(self):

        try:
            self.client.connect(self.addr)

            data_c = package.unpack(self.client.recv(2048))
            return data_c

        except:
            pass