Python socket programming Please do not copy and paste from previous Chegg answers Check server.py and client.py code and answer the questions below. # 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: \n") #Example: req = 'book2.txt, 5'   s.sendto(req.encode('ascii'), addr) print("Data requested.")   data, addr = s.recvfrom(buf) print(data.decode())   s.close()     # 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()   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 last line if the client didn't write a line number in their request. Example req = 'book2.txt'

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Python socket programming

Please do not copy and paste from previous Chegg answers

Check server.py and client.py code and answer the questions below.

# 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: \n")

#Example: req = 'book2.txt, 5'

 

s.sendto(req.encode('ascii'), addr)

print("Data requested.")

 

data, addr = s.recvfrom(buf)

print(data.decode())

 

s.close()

 

 

# 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()

 

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 last line if the client didn't write a line number in their request. Example req = 'book2.txt'

 

 

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Linux
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education