Esempio n. 1
0
    def handle_request(self, conn, addr):
        """ Handler request """
        while not self.__shutdown:
            conn.settimeout(5)
            try:
                message = parse_message(conn.recv)
                if not message:
                    break
                command, data = message
            except socket.timeout:
                break

            if command == 'connect':
                conn.sendall(make_message('connected', 'HELLO'))
            elif command == 'ping':
                conn.sendall(make_message('pong'))
            elif command == 'pingd':
                conn.sendall(make_message('pongd', data))
            elif command == 'quit':
                conn.sendall(make_message('ackquit', data))
                break
            elif command == 'finish':
                conn.sendall(make_message('ackfinish', data))
                self.__shutdown = True
                break

        if self.__shutdown:
            conn.sendall(make_message('ackfinish'))

        conn.close()
Esempio n. 2
0
    def handle_request(self, conn, addr):
        """ Handler request """
        while not self.__shutdown:
            conn.settimeout(5)
            try:
                message = parse_message(conn.recv)
                if not message:
                    break
                command, data = message
            except socket.timeout:
                break

            if command == 'connect':
                conn.sendall(make_message('connected', 'HELLO'))
            elif command == 'ping':
                conn.sendall(make_message('pong'))
            elif command == 'pingd':
                conn.sendall(make_message('pongd', data))
            elif command == 'quit':
                conn.sendall(make_message('ackquit', data))
                break
            elif command == 'finish':
                conn.sendall(make_message('ackfinish', data))
                self.__shutdown = True
                break

        if self.__shutdown:
            conn.sendall(make_message('ackfinish'))

        conn.close()
Esempio n. 3
0
 def send(self, command, message=''):
     self.socket.sendall(make_message(command, message))
Esempio n. 4
0
 def send(self, command, message=''):
     self.socket.sendall(make_message(command, message))