コード例 #1
0
from constants import *
from communication import Server, ClientConnection
from book_translator import *
from databases import ServerDatabase
import os

new_db = False

if not os.path.exists(DEFAULT_SERVER_DB_PATH):
    new_db = True
database = ServerDatabase(DEFAULT_SERVER_DB_PATH)
server = Server(database)
if new_db:
    server.users.signup('admin', 'admin', 0)
    with open('vlastelin.txt', encoding='utf-8') as book:
        server.books.add_book('Lipsum', book.read(), 0, '???')
server.start()
コード例 #2
0
ファイル: communication.py プロジェクト: emcraciu/PEP20G02
from random import randint

from communication import Client, Server
from utils.helpers import read_from_keyboard, prime_numbers

MAX_PRIME = 101
BASE = randint(17, MAX_PRIME)
TEXT = 'Text that will be sent'

primes = prime_numbers(MAX_PRIME)
prime = read_from_keyboard(primes)

server = Server(prime, BASE)
client = Client(prime, BASE, 'localhost')

server.start()
client.start()

client.send(TEXT)
server.stop()

assert TEXT == server.messages[0][1], 'Decrypt failed'