def handle(self):
        """
        Handles a TCP client
        """
        _logger.info(
            "RemoteConsole client connected: [%s]:%d",
            self.client_address[0],
            self.client_address[1],
        )

        # Prepare the session
        session = beans.ShellSession(
            beans.IOHandler(self.rfile, self.wfile),
            {"remote_client_ip": self.client_address[0]},
        )

        # Print the banner
        def get_ps1():
            """
            Gets the prompt string from the session of the shell service

            :return: The prompt string
            """
            try:
                return session.get("PS1")
            except KeyError:
                return self._shell.get_ps1()

        self.send(self._shell.get_banner())
        self.send(get_ps1())

        try:
            while self._active.get_value():
                # Wait for data
                rlist = select([self.connection], [], [], .5)[0]
                if not rlist:
                    # Nothing to do (poll timed out)
                    continue

                data = self.rfile.readline()
                if not data:
                    # End of stream (client gone)
                    break

                # Strip the line
                line = data.strip()
                if not data:
                    # Empty line
                    continue

                # Execute it
                try:
                    self._shell.handle_line(line, session)
                except KeyboardInterrupt:
                    # Stop there on interruption
                    self.send("\nInterruption received.")
                    return
                except IOError as ex:
                    # I/O errors are fatal
                    _logger.exception(
                        "Error communicating with a client: %s", ex
                    )
                    break
                except Exception as ex:
                    # Other exceptions are not important
                    import traceback

                    self.send("\nError during last command: {0}\n".format(ex))
                    self.send(traceback.format_exc())

                # Print the prompt
                self.send(get_ps1())
        finally:
            _logger.info(
                "RemoteConsole client gone: [%s]:%d",
                self.client_address[0],
                self.client_address[1],
            )

            try:
                # Be polite
                self.send("\nSession closed. Good bye.\n")
                self.finish()
            except IOError as ex:
                _logger.warning("Error cleaning up connection: %s", ex)
Handles a TCP client