Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

please solve it ASAP, make the answer simple for a helpful rating # Server from socket import * host = '127.0.0.1' port = 1234 s

please solve it ASAP, make the answer simple for a helpful rating

image text in transcribedimage text in transcribedimage text in transcribed
# Server from socket import * host = '127.0.0.1' port = 1234 s = socket(AF_INET,SOCK_DGRAM) s.bind((host,port)) addr = (host,port) buf=1024 data,addr = s.recvfrom(buf) data = data.decode() data = data.split(") f = open(data[0],'r') lines = f.readlines() index = int(data[1]) - 1 s.sendto(lines[index].encode('ascii"), addr) s.close()### Questions #1 - What modification(s) can you do to the code #1 and code #2 to make the server and client use the TCP Protocol? #2 - Modify the server code to send an error to the client if the file requested does not exist. #3 - Modify the server code to send an error to the client if the line requested does not exist. #4 - Modify the client code to request the first line if the client didn't write a line number in their request. Example req = 'book2.txt'Look at the code below and answer the questions (questions can be found under the code) # Client from socket import * s = socket(AF_INET, SOCK_DGRAM) host = '127.0.0.1' port = 1234 buf =1024 addr = (host,port) req = input("Enter the filename and the line number needed separated by comma: \ ") #Example: req = 'book2.txt, 5' s.sendto(req.encode('ascii'), addr) print("Data requested.") data, addr = s.recvfrom(buf) print(data.decode()) s.close()

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions