# 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 =...


Python language


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'


# Server<br>from socket import *<br>host = '127.0.0.1'<br>port = 1234<br>s = socket(AF_INET,SOCK_DGRAM)<br>s.bind((host,port))<br>addr = (host,port)<br>buf=1024<br>data,addr = s.recvfrom(buf)<br>data = data.decode()<br>data = data.split(',')<br>f = open(data[0],'r')<br>lines = f.readlines()<br>index = int(data[1]) - 1<br>s.sendto(lines[index].encode('ascii'), addr)<br>s.close()<br>

Extracted text: # 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()
Lab Exercises:<br>Write python program which create TCP connection between server and client<br>and do the following: (You need to use datetime, hashlib, random modules)<br>When the client connect to a server, it will send one of the following<br>commands ('time', 'md5 STRING', 'random')<br>The server will receive the command and based on the command will send<br>1.1.<br>1.2.<br>back data to the user:<br>1.2.1. Time: the server will send back the current time using the datetime<br>module.<br>1.2.2. MD5: the server will take the string along with the md5 word and<br>calculate the MD5 value for it and then send the hash to the client.<br>1.2.3. Random: the server will generate a random number between 1,100<br>and will send it back to the user.<br>

Extracted text: Lab Exercises: Write python program which create TCP connection between server and client and do the following: (You need to use datetime, hashlib, random modules) When the client connect to a server, it will send one of the following commands ('time', 'md5 STRING', 'random') The server will receive the command and based on the command will send 1.1. 1.2. 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 md5 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 1,100 and will send it back to the user.
Jun 07, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here