def main(): with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock: # This block offers user to choose the IP/Port combo, and makes sure a # connection is made to the specified combo address, port = None, None while port is None: try: address = input("Specify the address (empty or zero for local): ") port = int(input("Specify port (see users_manual for defaults): ")) assert port > 1024 and port < 65535 destination_address = (address, port) if address in ['', '127.0.0.1']: ask_user_between_test_and_real_server() sock.sendto(str.encode("\n"), destination_address) process_message.recv_msg(sock) except AssertionError as E: port = None print("port should be between 1024 and 65535, " "lower values reserved (except 0)") print(E) except OSError as E: port = None print(f"OSError occured: {E}") while True: try: data = input("What to send: ") # Connect to server and send data sock.sendto(str.encode(data), destination_address) #TODO: Not the best implementation received_messages = process_message.recv_msg(sock, False) print(f"Received: {received_messages}") except Exception as E: logging.exception("There was an exception")
def helper(data): sock.sendto(str.encode(data), destination_address) msgs = process_message.recv_msg(sock, print_msg=False) instrument = data.split(":")[2] no_command_msg = f'{instrument} is not a valid input. The valid ' \ f'inputs are "INTERLOCK", "HEXAPOD", "ASF", ' \ f'"POLAR", and "OTHER".' assert msgs[0] == no_command_msg
def helper(data): sock.sendto(str.encode(data), destination_address) msgs = process_message.recv_msg(sock, print_msg=False) mock_sr.get_message() value = float(data.rsplit(' ')[1]) # makes float of the str number # Assertions we care about assert isinstance(mock_sr.interlock_elevation, float) assert msgs[0] == f"Interlock elevation set to {value} deg" assert mock_sr.interlock_elevation == value assert mock_sr.interlock_reserved == 0.0 assert mock_sr.interlock_mode == 2000
def helper(data): sock.sendto(str.encode(data), destination_address) msgs = process_message.recv_msg(sock, print_msg=False) assert msgs[0] == interlock_msg
def helper(data, answer): sock.sendto(str.encode(data), destination_address) msgs = process_message.recv_msg(sock, print_msg=False) mock_sr.get_message() assert msgs[0] == answer
def helper(data): sock.sendto(str.encode(data), destination_address) msgs = process_message.recv_msg(sock, print_msg=False) return msgs