key_file = os.path.join(dir_path, f'{client_name}.key') if not os.path.exists(key_file): keys = RSA.generate(2048, os.urandom) with open(key_file, 'wb') as key: key.write(keys.export_key()) else: with open(key_file, 'rb') as key: keys = RSA.import_key(key.read()) # !!!keys.publickey().export_key() logger.debug("Keys sucsessfully loaded.") # Создаём объект базы данных database = ClientDatabase(client_name) # Создаём объект - транспорт и запускаем транспортный поток try: transport = ClientTransport(server_port, server_address, database, client_name, client_passwd, keys) logger.debug("Transport ready.") except ServerError as error: message = QMessageBox() message.critical(start_dialog, 'Ошибка сервера', error.text) sys.exit(1) transport.setDaemon(True) transport.start() # Удалим объект диалога за ненадобностью del start_dialog # Создаём GUI main_window = ClientMainWindow(database, transport, keys) main_window.make_connection(transport) main_window.setWindowTitle(f'Чат Программа alpha release - {client_name}')
client_name = start_dialog.client_name.text() del start_dialog else: exit(0) # Записываем логи logger.info( f'Запущен клиент с парамертами: адрес сервера: {server_address} , порт: {server_port}, имя пользователя: {client_name}' ) # Создаём объект базы данных database = ClientDatabase(client_name) # Создаём объект - транспорт и запускаем транспортный поток try: transport = ClientTransport(server_port, server_address, database, client_name) except ServerError as error: print(error.text) exit(1) transport.setDaemon(True) transport.start() # Создаём GUI main_window = ClientMainWindow(database, transport) main_window.make_connection(transport) main_window.setWindowTitle(f'Чат Программа alpha release - {client_name}') client_app.exec_() # Раз графическая оболочка закрылась, закрываем транспорт transport.transport_shutdown() transport.join()
dir_path = os.path.dirname(os.path.realpath(__file__)) key_file = os.path.join(dir_path, f'{account_name}.key') if not os.path.exists(key_file): keys = RSA.generate(2048, os.urandom) with open(key_file, 'wb') as key: key.write(keys.exportKey()) else: with open(key_file, 'rb') as key: keys = RSA.importKey(key.read()) keys.publickey().exportKey() database = ClientDatabase(account_name) try: transport = ClientTransport(PORT, ADDRESS, database, account_name, client_passwd, keys) except Exception as error: print(error) exit(1) transport.setDaemon(True) transport.start() main_window = ClientMainWindow(database, transport, keys) main_window.make_connection(transport) main_window.setWindowTitle(f'Чат Программа alpha release - {account_name}') client_app.exec_() transport.transport_shutdown() transport.join()
dir_path = os.path.dirname(os.path.realpath(__file__)) key_file = os.path.join(dir_path, f'{username}.key') if not os.path.exists(key_file): keys = RSA.generate(2048, os.urandom) with open(key_file, 'wb') as key_f: key_f.write(keys.export_key()) else: with open(key_file, 'rb') as key_f: keys = RSA.import_key(key_f.read()) CLIENT_LOG.debug('Keys loaded') db = ClientBase(username) try: transport = ClientTransport(port, address, db, username, password, keys) except ServerError as err: message = QMessageBox() message.critical(init_dialog, 'Server Error', str(err)) exit(1) transport.setDaemon(True) transport.start() del init_dialog window = ClientMainWindow(db, transport, keys) window.make_connection(transport) window.statusBar().showMessage('Connected to TEST server') app.exec_() transport.transport_shutdown()
ADDRESS, PORT, account_name = parse_comm_line() # client_main = ClientApp(ADDRESS, PORT, account_name) client_app = QApplication(sys.argv) if account_name is None: CLIENT_LOG.info('Запрашиваем имя у клиента') start_dialog = UserNameDialog() client_app.exec_() if start_dialog.ok_pressed: account_name = start_dialog.client_name.text() del start_dialog else: exit(0) database = ClientDatabase(account_name) try: transport = ClientTransport(PORT, ADDRESS, database, account_name) except Exception as error: print(error.text) exit(1) transport.setDaemon(True) transport.start() main_window = ClientMainWindow(database, transport) main_window.make_connection(transport) main_window.setWindowTitle(f'Чат Программа alpha release - {account_name}') client_app.exec_() transport.transport_shutdown() transport.join() # client_main()