def main(): """server main - handle the connection with the client and start a client handler thread when client is accept""" server = Server() # create server object v_port = 20001 a_port = 20002 zmq_port = 20003 database = Database() # create database while True: client_socket, address = server.sock.accept( ) # accept the client who connect server.rsa = RSACrypt() server.aes = AESEncryption() server.encryption_exchange_keys( client_socket) # exchange encryption keys with the client msg = str(v_port) + "*" + str(a_port) + "*" + str(zmq_port) client_socket.send( msg.encode() ) # sending communications ports for connection with the client handler msg = client_socket.recv(1024).decode() if msg == "first": first_time = True else: first_time = False client_hand = client_handler.ClientHandler(client_socket, v_port, a_port, zmq_port, database, server.aes, first_time) client_hand.start() # starts the client handler thread v_port += 3 a_port += 3 zmq_port += 3
def assign_handler(self, clientsocket, address): """ Creates a new ClientHandler object See also ClientHandler Class :param clientsocket: :param address: :return: a client handler object. """ handler = client_handler.ClientHandler(self, clientsocket, address) return handler
def handle_new_client(server_socket, client_socket, message_relay): """ Kicks off a new instance of ClientHandler in its own separate thread. params: server_socket client_socket message_relay """ client_handler = CH.ClientHandler(server_socket, client_socket, message_relay) client_handler.start()
def thread_client(self, clienthandler, addr): # init the client handler object ch = client_handler.ClientHandler(self, clienthandler, addr).init() ch.process_client_handler()
def newClient(soc,address): client_handler.ClientHandler(soc)