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)
# 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()
import select, socket, sys, pdb from pychat_util import Hall, Room, Player import pychat_util READ_BUFFER = 4096 hostname = socket.gethostname() IP = socket.gethostbyname(hostname) port = 7010 listen_sock = pychat_util.create_socket((IP, 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() hall.handle_msg(player, msg)
# 14-Jun-2013 import select, socket, sys, pdb from pychat_util import Hall, Room, Player import pychat_util READ_BUFFER = 4096 host = "127.0.0.1" 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)
# pychat_server.py # # Aaron Chan # CS494 (Spring 2018) # # Starts server and establishes incoming client connections import select, socket, sys, pdb import pychat_util, pychat_lobby from pychat_util import Room, Client from pychat_lobby import Lobby READ_BUFFER = 4096 listen_sock = pychat_util.create_socket((socket.gethostname(),pychat_util.PORT)) lobby = Lobby() connection_list = [] connection_list.append(listen_sock) while True: read_clients, write_clients, error_sockets = select.select(connection_list,[],[]) for client in read_clients: if client is listen_sock: # new client as connected new_socket, add = client.accept() new_client = Client(new_socket) connection_list.append(new_client) lobby.greet_new(new_client) lobby.clients_list.append(new_client) else: # new message from a client msg = client.socket.recv(READ_BUFFER)