Answered step by step
Verified Expert Solution
Question
1 Approved Answer
ANSWER IN PYTHON 3 AND SHOW OUTPUT PLEASE!!! Assignment Details: Starter Source Code: Programming Assignment 1: UDP Echo Client and Server NOTE: Before starting the
ANSWER IN PYTHON 3 AND SHOW OUTPUT PLEASE!!!
Assignment Details:
Starter Source Code:
Programming Assignment 1: UDP Echo Client and Server NOTE: Before starting the assignment, please see Submission Guidelines folder in Canvas with general instructions for implementing all assignments and format of submissions. Using UDP sockets, you will write a client and server program that enables the client to send a string of some specified length to the server over the network, and the server simply echoes back that string back to the client. The client program should take the following command-line parameters: IP address of server UDP port of server Length of string to be sent The client program will read in the above input parameters, initialize a string containing alphabetical characters of the specified length, and send the message using the UDP socket API to the server running at the specified IP address and port. If the client does not receive a message back from the server within a certain amount of time (one second), the client should retry up to a maximum number of tries (3) before terminating. The program output should print out trace information when data is sent and received, and account for error conditions. Client trace output must include: A message when data is sent to the server indicating destination IP address and port and length plus content of the data sent A message when data is received from the server indicating source IP address and port and contents of the data received An error message when any error occurs such as when a time-out occurs because the server is not running The server program should take the following command-line parameters: IP address that server listens on (127.0.0.1 will be used to test the program) UDP port that server listens on (e.g. 12000) The server will listen on the loopback address and the given port number, and be prepared to receive data from the client up to a fixed maximum length (100 bytes). The server will wait in an infinite loop to receive data from a client, and then send the received data back to the client without modification. Server trace output must include: A message when data is received from the client indicating source IP address and port and contents of the data received 1 The string may contain any value e.g. 'XXXXXXXXXX' 2 The socket API supports a timeout facility. See documentation on socket library relevant to programming language you are using. A message when data is sent back to the client indicating destination IP address and port Test Cases (both test cases must be demonstrated for full credit): 1. Test both client and server running on the same host, such as your computer (this should illustrate the client sending a single message and the server response) 2. Test client behavior when server is not running (this should illustrate the client sending 3 messages and timing out after each one). Note: In some operating systems, the client may exit with an error when sending to a non-existing server. To simulate this test case it may be necessary to run the server, but modify or comment out the code so that the server receives messages from the client, but does not send the messages back to the client. Example of the client trace output (server responds): Sending data to 127.0.0.1, 12000: XXXXXXXXXX (10 characters) Receive data from 127.0.0.1, 12000: XXXXXXXXXX Example of the client trace output (server does not respond): Sending data to 127.0.0.1, 12000: XXXXXXXXXX (10 characters) Message timed out Sending data to 127.0.0.1, 12000: XXXXXxxxxx (10 characters) Message timed out Sending data to 127.0.0.1, 12000: xxxxxxxxxx (10 characters) Message timed out Example of server trace output: The server is ready to receive on port: 12000 Receive data from client 127.0.0.1, 56777: XXXXXXXXXX Sending data to client 127.0.0.1, 56777: XXXXXXXXXX # ! /usr/bin/env python3 # Echo Client limport ... # Get the server hostname, port and data length as command line arguments host = sys.argv[1] port = int(sys.argv[2]) count = int(sys.argv[3]). data = 'X' * count # Initialize data to be sent # Create UDP client socket. Note the use of SOCK_DGRAM clientsocket = socket.socket (socket.AF_INET, socket.SOCK_DGRAM), # Send data to server print("Sending data to " + host + ", " + str(port) + ": " + data) clientsocket.sendto(data.encode(), (host, port), # Receive the server response dataEcho, address = clientsocket.recvfrom(count) print("Receive data from " + address[@] + ", " + str(address[1]) + ": " + dataEcho.decode() # Close the client socket clientsocket.close() #!/usr/bin/env python3 I# Echo Server limport ... # Read server IP address and port from command-line arguments serverIP = sys.argv[1] serverPort = int(sys.argv[2]), # Create a UDP socket. Notice the use of SOCK_DGRAM for UDP packets serverSocket = socket.socket (socket.AF_INET, socket. SOCK_DGRAM), # Assign server IP address and port number to socket serverSocket.bind((serverIP, serverPort)) print("The server is ready to receive on port: " + str(serverPort) + " "), # loop forever listening for incoming UDP messages while True: # Receive and print the client data from "data" socket data, address = serverSocket.recvfrom(1024), print("Receive data from client " + address[@] + ", " + str(address[1]) + ": " + data.decode()); # Echo back to client print("Sending data to client " + address[@] + ", " + str(address[1]) + ": " + data.decode() serverSocket.sendto(data, address) Programming Assignment 1: UDP Echo Client and Server NOTE: Before starting the assignment, please see Submission Guidelines folder in Canvas with general instructions for implementing all assignments and format of submissions. Using UDP sockets, you will write a client and server program that enables the client to send a string of some specified length to the server over the network, and the server simply echoes back that string back to the client. The client program should take the following command-line parameters: IP address of server UDP port of server Length of string to be sent The client program will read in the above input parameters, initialize a string containing alphabetical characters of the specified length, and send the message using the UDP socket API to the server running at the specified IP address and port. If the client does not receive a message back from the server within a certain amount of time (one second), the client should retry up to a maximum number of tries (3) before terminating. The program output should print out trace information when data is sent and received, and account for error conditions. Client trace output must include: A message when data is sent to the server indicating destination IP address and port and length plus content of the data sent A message when data is received from the server indicating source IP address and port and contents of the data received An error message when any error occurs such as when a time-out occurs because the server is not running The server program should take the following command-line parameters: IP address that server listens on (127.0.0.1 will be used to test the program) UDP port that server listens on (e.g. 12000) The server will listen on the loopback address and the given port number, and be prepared to receive data from the client up to a fixed maximum length (100 bytes). The server will wait in an infinite loop to receive data from a client, and then send the received data back to the client without modification. Server trace output must include: A message when data is received from the client indicating source IP address and port and contents of the data received 1 The string may contain any value e.g. 'XXXXXXXXXX' 2 The socket API supports a timeout facility. See documentation on socket library relevant to programming language you are using. A message when data is sent back to the client indicating destination IP address and port Test Cases (both test cases must be demonstrated for full credit): 1. Test both client and server running on the same host, such as your computer (this should illustrate the client sending a single message and the server response) 2. Test client behavior when server is not running (this should illustrate the client sending 3 messages and timing out after each one). Note: In some operating systems, the client may exit with an error when sending to a non-existing server. To simulate this test case it may be necessary to run the server, but modify or comment out the code so that the server receives messages from the client, but does not send the messages back to the client. Example of the client trace output (server responds): Sending data to 127.0.0.1, 12000: XXXXXXXXXX (10 characters) Receive data from 127.0.0.1, 12000: XXXXXXXXXX Example of the client trace output (server does not respond): Sending data to 127.0.0.1, 12000: XXXXXXXXXX (10 characters) Message timed out Sending data to 127.0.0.1, 12000: XXXXXxxxxx (10 characters) Message timed out Sending data to 127.0.0.1, 12000: xxxxxxxxxx (10 characters) Message timed out Example of server trace output: The server is ready to receive on port: 12000 Receive data from client 127.0.0.1, 56777: XXXXXXXXXX Sending data to client 127.0.0.1, 56777: XXXXXXXXXX # ! /usr/bin/env python3 # Echo Client limport ... # Get the server hostname, port and data length as command line arguments host = sys.argv[1] port = int(sys.argv[2]) count = int(sys.argv[3]). data = 'X' * count # Initialize data to be sent # Create UDP client socket. Note the use of SOCK_DGRAM clientsocket = socket.socket (socket.AF_INET, socket.SOCK_DGRAM), # Send data to server print("Sending data to " + host + ", " + str(port) + ": " + data) clientsocket.sendto(data.encode(), (host, port), # Receive the server response dataEcho, address = clientsocket.recvfrom(count) print("Receive data from " + address[@] + ", " + str(address[1]) + ": " + dataEcho.decode() # Close the client socket clientsocket.close() #!/usr/bin/env python3 I# Echo Server limport ... # Read server IP address and port from command-line arguments serverIP = sys.argv[1] serverPort = int(sys.argv[2]), # Create a UDP socket. Notice the use of SOCK_DGRAM for UDP packets serverSocket = socket.socket (socket.AF_INET, socket. SOCK_DGRAM), # Assign server IP address and port number to socket serverSocket.bind((serverIP, serverPort)) print("The server is ready to receive on port: " + str(serverPort) + " "), # loop forever listening for incoming UDP messages while True: # Receive and print the client data from "data" socket data, address = serverSocket.recvfrom(1024), print("Receive data from client " + address[@] + ", " + str(address[1]) + ": " + data.decode()); # Echo back to client print("Sending data to client " + address[@] + ", " + str(address[1]) + ": " + data.decode() serverSocket.sendto(data, address)Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started