Question: Write python program which create TCP connection between server and client and do the following: (You need to use datetime, hashlib, random modules) 1.1. When

 Write python program which create TCP connection between server and clientand do the following: (You need to use datetime, hashlib, random modules)1.1. When the client connect to a server, it will send one

Write python program which create TCP connection between server and client and do the following: (You need to use datetime, hashlib, random modules) 1.1. When the client connect to a server, it will send one of the following commands ('time', 'md5 STRING', 'random x,y ') 1.2. The server will receive the command and based on the command will send back data to the user: 1.2.1. Time: the server will send back the current time using the datetime module. 1.2.2. MD5: the server will take the string along with the 'hash' word and calculate the MD5 value for it and then send the hash to the client. 1.2.3. Random: the server will generate a random number between x,y and will send it back to the user. 2.Check server.py and client.py code and answer the questions below. \# Client from socket import * \[ \begin{array}{l} s=\text { socket }(\text { AF INET, SOCK_DGRAM) } \\ \text { host }=' 127.0 .0 .1 ' \\ \text { port }=1234 \\ \text { buf }=1024 \\ \text { addr }=\text { (host.port) } \end{array} \] req = input ("Enter the filename and the line number needed separated by comma: n ") \#Example: req = 'book2.txt, 5 susendto(reg.encode('ascii'), addr) print("Data requested. ") data, addr = s.recyfrom(buf) print(data.decode0) s.close 0 \# 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 = sarecvfrom(buf) data = data.decode0 data = data.split(',') f=open(data[0],'r') lines = f,readlines( index = int(datal] 1])1 s.sendto(lines[index].encode('ascii'), addr) s.close0 - 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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!