def supply_sample_bank_servers(self): accounts1 = Contents([[1234, "AccountOwner1", 100], [2345, "AccountOwner2", 10]]) accounts2 = Contents([[3456, "AccountOwner3", 1000], [4567, "AccountOwner4", 10000]]) server_list = [ Server(1, "Bank 1", "Bank", "1.1.1.1", 2, accounts1), Server(2, "Bank 2", "Bank", "2.2.2.2", 2, accounts2) ] return server_list
def supply_sample_file_servers(self): contents1 = Contents([["file1.dat", "Some text data", 12], ["file2.dat", "Some text data", 5], ["file3.dat", "Some text data", 3]]) contents2 = Contents([["file1.dat", "Some text data", 12], ["file5.dat", "Some text data", 5], ["file6.dat", "Some text data", 3]]) server_list = [ Server(1, "Test Server 1", "File", "1.1.1.1", 1, contents1), Server(2, "Test Server 2", "File", "2.2.2.2", 1, contents2) ] return server_list
def serverWorker(): while True: global server global settings global userRequestedStop time.sleep(1) psLogger.debug("New server worker") try: if userRequestedStop is False: settings = getSettings() #Should verify settings if settings is False: psLogger.error("Could not find settings") break server = Server(settings) server.run() except ServerStoppedByUser: psLogger.debug("Server stopped by user") except Exception as e: psLogger.error("Server encountered error: {}".format(e)) server = None time.sleep(5)
def main(): print(HEADER) while True: print("\nLaunch :") print("[1] Server") print("[2] Client") print("[3] Help") print("[4] Exit") user_input = input("\n> ") if user_input == "1": print("\nServer :") print("[1] Default settings") print("[2] Last used settings") print("[3] Custom settings") print("[4] Back") while True: user_input = input("\n> ") if user_input == "1": server = Server() server.show() server.run() break elif user_input == "2": settings = get_settings("server") host, port, max_users, buff_size, log_enabled, width, height = list( settings.values()) server = Server() server.show() server.run() break elif user_input == "3": host = input("[1/7] Host (def. = 127.0.0.1) : ") port = input("[2/7] Port (def. = 9999) : ") max_users = input("[3/7] Max. users (def. = 5) : ") buff_size = input("[4/7] Buffer size (def. = 4096) : ") log_enabled = input( "[5/7] Enable log (y/n) (def. = True) :") width = input("[6/7] width (def. = 80) : ") height = input("[7/7] height (def. = 30) : ") server = Server(host, port, max_users, buff_size, log_enabled) server.show(width, height) server.run() break elif user_input == "4": break else: print("Invalid number, pleaser enter 1, 2 or 3.") elif user_input == "2": print("\nClient :") print("[1] Default settings") print("[2] Last used settings") print("[3] Custom settings") print("[4] Back") while True: user_input = input("\n> ") if user_input == "1": username = input("Username : "******"2": settings = get_settings("client") username, log_enabled, encoding, encoding_errors, buff_size, width, height = list( settings.values()) client = Client() client.show() client.connect() break elif user_input == "3": username = input("[1/7] Username : "******"[2/7] Enable log (y/n) (def. = True) : ") encoding = input("[3/7] Encoding (def. = utf-8) : ") encoding_errors = input( "[4/7] Encoding errors handling (def. = replace) : ") buff_size = input("[5/7] Buffer size (def. = 4096) : ") width = input("[6/7] width (def. = 80) : ") height = input("[7/7] height (def. = 30) : ") client = Client(username, log_enabled, encoding, encoding_errors, buff_size) client.show(width, height) client.connect() break elif user_input == "4": break else: print("Invalid number, pleaser enter 1, 2 or 3.") elif user_input == "3": print("\nHelp :") print("help") print("[PRESS ENTER TO RETURN TO THE MAIN MENU]") input() elif user_input == "4": exit() else: print("Invalid number, pleaser enter 1, 2 or 3.")
#!/usr/bin/python from classes.Server import Server from classes.LogBuffer import LogBuffer import os oServer = Server() nPid = os.getpid() while 1: # Se sono nel processo figlio elaboro la richiesta trasmessa dal padre if nPid == 0: bOk = oServer.elabora(oClient) if not bOk: LogBuffer.write("Errore durante l'elaborazione della richiesta",3) else: LogBuffer.write("Richiesta elaborata correttamente",4) # Termino l'esecuzione del processo os._exit(0) else: print("Ascolto...") try: # Cosa fa : Attende di ricevere dei dati # Ritorna : oClient -> tupla che identifica il client, così formata # [0] => socket, oggetto socket riferito al client. Identifica la connessione con il client # [1] => address
from classes.Server import Server server = Server() server.listen()
# Work only on python 2 because using pickle and bytes difference in between python versions. assert (sys.version_info.major == 2) logging.basicConfig(stream=sys.stdout, level=logging.DEBUG) signal.signal(signal.SIGINT, signal.SIG_DFL) car, rps_ms, port = load_car("config.json") h = [ (r"/action", Action.Action, { 'car': car }), (r"/state", State.State, { 'car': car, 'rps_ms': rps_ms, 'for_network': True }) # rps_ms: Request Per Seconds Millisecond ] if __name__ == "__main__": try: logging.debug("main.py called") #rc = RegisterCar() #rc.register_car(socket.gethostname()) s = Server(h, port=port) s.start() except KeyboardInterrupt: #rc.unregister_car() print "Exiting"
# coding:utf-8 from classes.Server import Server server = Server() server.start() while True: data = input('Send File: ') server.send_file(data)
PROCESSORS.append( Processor("Insmell PC10000", "Ultra Industrial Processor", 3000, 1, 10000)) # Qualifications QUALIFICATIONS.append(Qualification("Network Security", "Class 1")) QUALIFICATIONS.append(Qualification("Network Security", "Class 2")) QUALIFICATIONS.append(Qualification("Network Security", "Class 3")) QUALIFICATIONS.append(Qualification("Network Security", "Class 4")) QUALIFICATIONS.append(Qualification("Software Developer", "Class 1")) QUALIFICATIONS.append(Qualification("Software Developer", "Class 2")) QUALIFICATIONS.append(Qualification("Software Developer", "Class 3")) QUALIFICATIONS.append(Qualification("Software Developer", "Class 4")) # Servers SERVERS.append( Server(1, "Server A", "file", "192.192.192.192", 1, Contents(["File A.txt", "File B.txt", "File C.jpg"]))) SERVERS.append( Server( 2, "Server B", "bank", "10.10.10.10", 2, Contents([["1234", "John Smith", 123.45], ["2345", "Suzie Sanders", 524.12]]))) SERVERS.append( Server( 3, "Server C", "database", "10.80.3.18", 2, Contents([["Steve", "Smith", "9876 Somewhere St.", "St. Louis", "MO"], ["Jim", "Jones", "123 Middle Rd.", "Indianapolis", "IN"]]))) # Workstations WORKSTATIONS.append( Workstation("Standard Desktop PC", "Standard performance PC", 500, 4, [DISKS[1], MEMORY[1], NETWORKS[1], PROCESSORS[1]]))