Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

cCOMPUTER NETWORKING SOFTWARE CONCEPTS: UDP UNICAST Objectives:To demonstration knowledge of UDP unicast by writing code to do so. Directions: Fill in the relevant portions of

image text in transcribedimage text in transcribedcCOMPUTER NETWORKING SOFTWARE CONCEPTS: UDP UNICAST

Objectives:To demonstration knowledge of UDP unicast by writing code to do so.

Directions: Fill in the relevant portions of the provided skeleton file to complete the assignment and make it function as desired

import argparse, socket, sys MAX_BYTES = 65535 # Server def server(interface, port): #@ make the appropriate socket using the socket module and assign it to the variable sock #@ invoke the bind method on the sock and pass in the pair consisting of the interface and the port #@ invoke the getsockname method on the sock and print that out so that the user can know where we are listening while True: #@ invoke the recyfrom method on the sock and pass in the maximum number of bytes that we would want to receive # note that the above returns two values, which get assigned to two variables, data is one variable and address is the other text = data.decode('ascii) print('The client at {} says {r}',format(address, text)) message = 'Your data was {} bytes long'.format(len(data)) encoded_message = message.encode('ascii') 4@ invoke the sendto method on the sock object, and pass in the two parameters of the encoded message and the address # client def client (hostname, port): #@ make the appropriate socket using the socket module and assign it to the variable sock hostname = sys. aray[2] #@ invoke the connect method on the sock object and pass in the pair consisting of the hostname and port #@ print out the result of calling the getsockname method of the sock object and do so in a manner that is friendly to the user delay = 0.1 # seconds text = input("What data should we send to the server?") # send datagram while more to send while lon(text): data = text.encode('ascii') # send datagram to server while True: #@ invoke the send method on the sock object to send the data print('Waiting up to {} seconds for a reply'.format(delay)) #@ invoke the settimeout method on the sock object to set the delay to the appropriate value try: #@ invoke the recy method on the sock object to receive at most MAX_BYTES and to assign the bytes received to the variable data except socket. timeout as exc: delay *= 2 # wait even longer for the next request if delay > 2.0: raise RuntimeError('I think the server is down') #from exc else: break we are done, and can stop looping print('The server says {!r}'.format(data.decode('ascii'))) # get next datagram to send text = input("What data should we send to the server?") # main if name = 'main ': choices = {'client': client, 'server': server) parser - argparse. ArgumentParser(description='Send and receive UDP') parser.add_argument('role', choices=choices, help='which role to take') # main if __name__ == '__main__': choices = {'client': client, 'server': server} parser = argparse. ArgumentParser(description='Send and receive UDP') parser. add_argument('role', choices=choices, help='which role to take') parser.add_argument('host', help='interface the server listens at;' I host the client sends to') parser.add_argument('-p', metavar='PORT', type=int, default=1060, help='UDP port (default 1060)') args = parser.parse_args(). function = choices[args.role] function(args.host, args.p) import argparse, socket, sys MAX_BYTES = 65535 # Server def server(interface, port): #@ make the appropriate socket using the socket module and assign it to the variable sock #@ invoke the bind method on the sock and pass in the pair consisting of the interface and the port #@ invoke the getsockname method on the sock and print that out so that the user can know where we are listening while True: #@ invoke the recyfrom method on the sock and pass in the maximum number of bytes that we would want to receive # note that the above returns two values, which get assigned to two variables, data is one variable and address is the other text = data.decode('ascii) print('The client at {} says {r}',format(address, text)) message = 'Your data was {} bytes long'.format(len(data)) encoded_message = message.encode('ascii') 4@ invoke the sendto method on the sock object, and pass in the two parameters of the encoded message and the address # client def client (hostname, port): #@ make the appropriate socket using the socket module and assign it to the variable sock hostname = sys. aray[2] #@ invoke the connect method on the sock object and pass in the pair consisting of the hostname and port #@ print out the result of calling the getsockname method of the sock object and do so in a manner that is friendly to the user delay = 0.1 # seconds text = input("What data should we send to the server?") # send datagram while more to send while lon(text): data = text.encode('ascii') # send datagram to server while True: #@ invoke the send method on the sock object to send the data print('Waiting up to {} seconds for a reply'.format(delay)) #@ invoke the settimeout method on the sock object to set the delay to the appropriate value try: #@ invoke the recy method on the sock object to receive at most MAX_BYTES and to assign the bytes received to the variable data except socket. timeout as exc: delay *= 2 # wait even longer for the next request if delay > 2.0: raise RuntimeError('I think the server is down') #from exc else: break we are done, and can stop looping print('The server says {!r}'.format(data.decode('ascii'))) # get next datagram to send text = input("What data should we send to the server?") # main if name = 'main ': choices = {'client': client, 'server': server) parser - argparse. ArgumentParser(description='Send and receive UDP') parser.add_argument('role', choices=choices, help='which role to take') # main if __name__ == '__main__': choices = {'client': client, 'server': server} parser = argparse. ArgumentParser(description='Send and receive UDP') parser. add_argument('role', choices=choices, help='which role to take') parser.add_argument('host', help='interface the server listens at;' I host the client sends to') parser.add_argument('-p', metavar='PORT', type=int, default=1060, help='UDP port (default 1060)') args = parser.parse_args(). function = choices[args.role] function(args.host, args.p)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Seven NoSQL Databases In A Week Get Up And Running With The Fundamentals And Functionalities Of Seven Of The Most Popular NoSQL Databases

Authors: Aaron Ploetz ,Devram Kandhare ,Sudarshan Kadambi ,Xun Wu

1st Edition

1787288862, 978-1787288867

More Books

Students also viewed these Databases questions

Question

What is the purpose of the report?

Answered: 1 week ago

Question

25.0 m C B A 52.0 m 65.0 m

Answered: 1 week ago

Question

1. Describe the power of nonverbal communication

Answered: 1 week ago