Пример #1
0
    def __init__(self, host, port):
        super(BaseServer, self).__init__()

        self.tcp_server = QTcpServer(self)

        if not self.tcp_server.listen(QHostAddress(host), port):
            log_error('Unable to start the server: {0}.'.format(
                self.tcp_server.errorString()))
            self.exec_()
            return

        log_info('The server is running on port {0}.'.format(
            self.tcp_server.serverPort()))

        self.connect(self.tcp_server, SIGNAL('newConnection()'),
                     self.new_connection)

        self.connections = []
        self.users = {}

        self.commands = {}
        self._add_command('ONLINE', self._command_online)
        self._add_command('OFFLINE', self._command_offline)
        self._add_command('ECHO', self._command_echo)
        self._add_command('USERS', self._command_users)
Пример #2
0
 def _command_echo(self, command, message):
     log_info('ECHO (command): %s' % message)
Пример #3
0
 def default_log(self, text):
     with open(os.path.join(LOG_FOLDER, 'default_log.log'), 'a') as f:
         f.write('%s\n' % self.get_message(text))
         if LOG:
             log_info(self.get_message(text))
Пример #4
0
 def _command_echo(self, client, command, message):
     log_info('ECHO (command): Client: {}, command: {}, message: {}'.format(
         client.socketDescriptor(), command, message))