Exemple #1
0
    def __init__(self, host):
        """ Initialize the server paramater """

        # Intialize the new connection listening port
        self.READ_BUFFER = 4096
        self.listen_sock = pychat_util.create_socket((host, pychat_util.PORT))

        # Create ECC parameter input window
        # Wait until parameter is entered
        param = ECCParam()
        while not param.param_set : pass

        # Initialize the ECC curve, and generate the secret key
        #self.curve = ECCipher(-1, 188, 7919, Point(224, 503), 20)
        self.curve = ECCipher(param.a_val, param.b_val, param.p_val, Point(param.pt_x, param.pt_y), param.k_val)
        self.secret_key = self.curve.gen_fancy_des_secret_key()

        # Initialize the server's Hall and the connection list
        self.hall = Hall(self.curve.gen_fancy_des_partial_key(self.secret_key))
        self.connection_list = []
        self.connection_list.append(self.listen_sock)
Exemple #2
0
# implementing 3-tier structure: Hall --> Room --> Clients;
# 14-Jun-2013

import select, socket, sys, pdb
from pychat_util import Hall, Room, Player
import pychat_util

READ_BUFFER = 4096

host = sys.argv[1] if len(sys.argv) >= 2 else ''
listen_sock = pychat_util.create_socket((host, pychat_util.PORT))

hall = Hall()
connection_list = []
connection_list.append(listen_sock)

while True:
    # Player.fileno()
    read_players, write_players, error_sockets = select.select(
        connection_list, [], [])
    for player in read_players:
        if player is listen_sock:  # new connection, player is a socket
            new_socket, add = player.accept()
            new_player = Player(new_socket)
            connection_list.append(new_player)
            hall.welcome_new(new_player)

        else:  # new message
            msg = player.socket.recv(READ_BUFFER)
            if msg:
                msg = msg.decode().lower()