msg_raw = cs.recv(2048) msg = msg_raw.decode() formatted_message = server_utils.format_command(msg) print(formatted_message) formatted_message = formatted_message.split(" ") if len(formatted_message) == 1: command = formatted_message[0] else: command = formatted_message[0] argument = formatted_message[1] if formatted_message == "PING": server_utils.ping(cs) elif command == "GET": server_utils.get(cs, l_seqs, argument) elif command == "INFO": server_utils.info(cs, argument) elif command == "COMP": server_utils.comp(cs, argument) elif command == "REV": server_utils.rev(cs, argument) elif command == "GENE": server_utils.gene(cs, argument)
print("Waiting for clients!") try: (client_socket, client_ip_port) = sl.accept() except KeyboardInterrupt: print("Server stopped by the user") sl.close() exit() else: msg_bytes = client_socket.recv(2048) msg_string = msg_bytes.decode() useful_string = server_utils.modified_message(msg_string) separate_strings = useful_string.split(" ") if "PING" == server_utils.modified_message(msg_string): server_utils.ping(client_socket) elif separate_strings[0] == "GET": server_utils.get_sequence(client_socket, int(separate_strings[1]), seq_list) elif separate_strings[0] == "INFO": server_utils.info(client_socket, separate_strings[1]) elif separate_strings[0] == "COMP": server_utils.complementary(client_socket, separate_strings[1]) elif separate_strings[0] == "REV": server_utils.reverse(client_socket, separate_strings[1]) elif separate_strings[0] == "GENE":
msg_raw = cs.recv(2048) # -- We decode it for converting it # -- into a human-redeable string msg = msg_raw.decode() formatted_message = server_utils.format_command(msg) formatted_message = formatted_message.split(" ") if len(formatted_message) == 1: command = formatted_message[0] else: command =formatted_message[0] argument = formatted_message[1] if command == "PING": response = 'OK!\n' server_utils.ping() # -- The message has to be encoded into bytes cs.send(response.encode()) if command == 'GET': if argument == '0': server_utils.get(cs, list_sequences, 0) elif argument == '1': server_utils.get(cs, list_sequences, 1) elif argument == '2': server_utils.get(cs, list_sequences, 2) elif argument == '3': server_utils.get(cs, list_sequences, 3) elif argument == '4': server_utils.get(cs, list_sequences, 4) if command == 'INFO': server_utils.info_send(cs, argument)
print("SEQ Server up!") while True: print("Awaiting client...") try: (cs, client_ip_port) = ls.accept() except KeyboardInterrupt: print("Server stopped by the user") ls.close() exit() else: # print("A client has connected to the server!") msg = utils.format_command(cs.recv(2048).decode()) if msg == "PING": res = "OK!" # print(termcolor.colored("PING command!", "green")) utils.ping() elif "GET" in msg: res = list_seq[int(msg[-1])] utils.print_colored("GET", "green") elif "INFO" in msg: utils.print_colored("INFO", "green") res = utils.info(msg.replace("INFO ", "")) elif "COMP" in msg: utils.print_colored("COMP", "green") res = utils.comp(msg.replace("COMP ", "")) elif "REV" in msg: utils.print_colored("REV", "green") res = utils.rev(msg.replace("REV ", "")) elif "GENE" in msg: utils.print_colored("GENE", "green") res = utils.gene(msg.replace("GENE ", "../P0/Sequences/"))