Stuck on how to complete my code as I keep getting errors. Here are the instructions and my code so far. Please answer in Python. Thank you. • Replace the user-specified number of messages to be sent with a variable numMsgs that you can define internally in your program. We will set numMsgs according to the experiments specified below. • Replace the user-specified message string with a string of the size defined by the experiments below. Please utilize the following example that allows us to create a string comprising of null values of a size specified using the variable numBytes. In the following example, we are creating a string called message of a 1000 bytes. We can similarly create a message string of 5000 and 10000 Bytes by changing the value of numBytes. numBytes = 1000 message = ‘\x00’ * numBytes To get the size of this message (needed later as a part of your code output), you may use the getsizeof utility from the system library in Python. Please import the system library as ‘import sys’. The following example shows how to get the size of the message we created earlier: sys.getsizeof(message)   • Create and use variables, timeBefore and timeAfter, to measure the time BEFORE and AFTER each sendto( ) call sending a message to the server. Use the time( )function in Python to measure the time. This function returns the current time in seconds since the "epoch." The epoch is a reference point in time, and the specific epoch used by Python is the "Unix epoch," which is defined as 00:00:00 Coordinated Universal Time (UTC) on January 1, 1970. When time( ) function is called, it returns a floating-point number representing the number of seconds that have passed since January 1, 1970 (the Unix epoch) to the current time. We can call the time( ) function at multiple points in our program to find the time difference between these points. To use the time function, import the time library as ‘import time’. The following example shows how to store a time value in a variable timeBefore: timeBefore = time.time( ) • Create a variable RTT that measures the round trip time for each message within the message sending loop. • Create a variable SeqNum that reflects the sequence number of each message sent from client to the server. • For each message received from the server in response to a message sent from the client, display a message of the type: Message sequence number with size received from with round trip time seconds. Here’s a sample output from my client code: Message sequence 1 with size 5049 received from ('127.0.0.1', 12001) with RTT 0.0018 s. Message sequence 2 with size 5049 received from ('127.0.0.1', 12001) with RTT 0.0033 s. Message sequence 3 with size 5049 received from ('127.0.0.1', 12001) with RTT 0.0025 s. Message sequence 4 with size 5049 received from ('127.0.0.1', 12001) with RTT 0.0037 s. Message sequence 5 with size 5049 received from ('127.0.0.1', 12001) with RTT 0.0041 s. import socket import sys import time def udp_echo_client():     # Create a UDP socket     client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)     server_address = ('localhost', 65432) def send_message(message):     timeBefore = time.time( )     send_message_socket.send(message)     timeAfter = time.time( )     RTT = timeAfter - timeBefore     sys.getsizeof(message)     # Get user input     numMSGS = int(input("How many times would you like to send the message? "))     nunBytes = 1000     message = numMSGS * numBytes     seqNum += 1     print("Message sequence number", , "with size", , "received from", , "with round trip time", , "seconds")     for _ in range(num_times):         # Send data to the server         sent = client_socket.sendto(message.encode(), server_address)         # Receive response from the server         data, server = client_socket.recvfrom(4096)         print(f"Received echo: '{data.decode()}' from {server}") if __name__ == "__main__":     udp_echo_client()

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
icon
Concept explainers
Question
Stuck on how to complete my code as I keep getting errors. Here are the instructions and my code so far. Please answer in Python. Thank you.
• Replace the user-specified number of messages to be sent with a variable numMsgs that you
can define internally in your program. We will set numMsgs according to the experiments
specified below.
• Replace the user-specified message string with a string of the size defined by the
experiments below. Please utilize the following example that allows us to create a string
comprising of null values of a size specified using the variable numBytes.
In the following example, we are creating a string called message of a 1000 bytes. We can
similarly create a message string of 5000 and 10000 Bytes by changing the value of
numBytes.
numBytes = 1000
message = ‘\x00’ * numBytes
To get the size of this message (needed later as a part of your code output), you may use the
getsizeof utility from the system library in Python. Please import the system library as ‘import
sys’. The following example shows how to get the size of the message we created earlier:
sys.getsizeof(message)
 
• Create and use variables, timeBefore and timeAfter, to measure the time BEFORE and AFTER
each sendto( ) call sending a message to the server.
Use the time( )function in Python to measure the time. This function returns the current time
in seconds since the "epoch." The epoch is a reference point in time, and the specific epoch
used by Python is the "Unix epoch," which is defined as 00:00:00 Coordinated Universal
Time (UTC) on January 1, 1970. When time( ) function is called, it returns a floating-point
number representing the number of seconds that have passed since January 1, 1970 (the
Unix epoch) to the current time. We can call the time( ) function at multiple points in our
program to find the time difference between these points.
To use the time function, import the time library as ‘import time’. The following example
shows how to store a time value in a variable timeBefore:
timeBefore = time.time( )
• Create a variable RTT that measures the round trip time for each message within the
message sending loop.
• Create a variable SeqNum that reflects the sequence number of each message sent from
client to the server.
• For each message received from the server in response to a message sent from the client,
display a message of the type: Message sequence number <seqNum> with size <message
size> received from <server address> with round trip time <RTT> seconds.
Here’s a sample output from my client code:
Message sequence 1 with size 5049 received from ('127.0.0.1', 12001) with RTT 0.0018 s.
Message sequence 2 with size 5049 received from ('127.0.0.1', 12001) with RTT 0.0033 s.
Message sequence 3 with size 5049 received from ('127.0.0.1', 12001) with RTT 0.0025 s.
Message sequence 4 with size 5049 received from ('127.0.0.1', 12001) with RTT 0.0037 s.
Message sequence 5 with size 5049 received from ('127.0.0.1', 12001) with RTT 0.0041 s.

import socket
import sys
import time

def udp_echo_client():
    # Create a UDP socket
    client_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    server_address = ('localhost', 65432)
def send_message(message):
    timeBefore = time.time( )
    send_message_socket.send(message)
    timeAfter = time.time( )
    RTT = timeAfter - timeBefore
    sys.getsizeof(message)


    # Get user input
    numMSGS = int(input("How many times would you like to send the message? "))
    nunBytes = 1000
    message = numMSGS * numBytes
    seqNum += 1
    print("Message sequence number", <seqNum>, "with size", <message size>, "received from", <server address>, "with round trip time", <RTT>, "seconds")

    for _ in range(num_times):
        # Send data to the server
        sent = client_socket.sendto(message.encode(), server_address)

        # Receive response from the server
        data, server = client_socket.recvfrom(4096)
        print(f"Received echo: '{data.decode()}' from {server}")

if __name__ == "__main__":
    udp_echo_client()

Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
Operators
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY