Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Attached are UDP client and server programs written in Python. To run the python programs on Linux, type python p1_udp_client.py and python p1_udp_server.py for each

Attached are UDP client and server programs written in Python. To run the python programs on Linux, type "python p1_udp_client.py" and "python p1_udp_server.py" for each terminal. " p1_udp_client.py" and "python p1_udp_server.py" have tested on Python 2.7.12. p1_udp_server_3.py and p1_udp_client_3.py have been tested on Python 3.5.2. Please check your python version first.

Modify the UDP client and server posted above.

  1. The UDP client sends 20 messages to the UDP server. (10 Points)

  2. The UDP server replies to the client whenever 5 messages are received (or delivered), so the client receives only 5 messages from the server. (40 Points)

  3. The UDP server does not reply if any of 5 messages is not delivered. (50 Points).

*

############################## # UDP Echo Clinet ############################### import socket import sys

# Create a UDP socket sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) server_address = ('localhost', 10000)

# for checking a number of messages count = 0

try: while True: message = sys.stdin.readline().replace(' ','') # Send data sys.stderr.write('sending "%s" ' % message) sent = sock.sendto(message.encode(), server_address) count = count + 1 if message.lower() == 'exit': break

# Receive response sys.stderr.write('waiting to receive ') data, server = sock.recvfrom(4096) sys.stderr.write('received "%s" ' % data.decode())

finally: sys.stderr.write('closing socket ') sock.close()

############################### # UDP Echo Server ############################### import socket import sys

# Create a datagram socket sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

# Bind the socket to the port (port number: 10000) server_address = ('localhost', 10000) sys.stderr.write('starting up on %s port %s ' % server_address) sock.bind(server_address)

# for checking a number of messages count = 0

while True: sys.stderr.write('waiting to receive message ') data, address = sock.recvfrom(4096) sys.stderr.write('received %s bytes from %s ' % (len(data), address)) sys.stderr.write(data.decode()) if data: if data.lower() == 'exit': break else: sent = sock.sendto(data, address) sys.stderr.write(' sent %s bytes back to %s ' % (sent, address))

sock.close()

* This is the code

*Okay do 4 messages*

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

Students also viewed these Databases questions