Question: Update the following code to avoid ( a ) plagiarism and ( b ) so the server can present the following questions to the clients
Update the following code to avoid a plagiarism and b so the server can present the following questions to the clients and the clients can ask the questions as many times as the clients want the server should always provide the answer without interruption and if the query's answer is not stored in the server, the server should provide invalid query. Update both the server and client program:
server.py
# import socket programming library
import socket
# import thread module
from thread import
import threading
printlock threading.Lock
# thread function
def threadedc:
while True:
# data received from client
data crecv
if not data:
printBye
# lock released on exit
printlock.release
break
# reverse the given string from client
data data::
# send back reversed string to client
csenddata
# connection closed
cclose
def Main:
host
# reserve a port on your computer
# in our case it is but it
# can be anything
port
s socket.socketsocketAFINET, socket.SOCKSTREAM
sbindhost port
printsocket binded to port", port
# put the socket into listening mode
slisten
printsocket is listening"
# a forever loop until client wants to exit
while True:
# establish connection with client
c addr saccept
# lock acquired by client
printlock.acquire
printConnected to : addr: addr
# Start a new thread and return its identifier
startnewthreadthreadedc
sclose
if namemain:
Main
questions and answers to include in the server:
# Questions and their corresponding answers
QUESTIONS
: What is the minimum and maximum length of a TCP header?",
"The minimum TCP header length is bytes, and the maximum is bytes."
: What is the purpose of the threeway handshake in TCP
"The threeway handshake establishes a reliable connection between the client and server."
: What is the difference between TCP and UDP?",
TCP is connectionoriented and reliable, whereas UDP is connectionless and faster."
: What are the main flags in a TCP segment header, and what do they signify?",
"Flags include SYN ACK, FIN, RST and others, used for connection control."
: How does TCP ensure reliable data transfer?",
TCP uses acknowledgments, retransmissions, and sequence numbers."
client.py
# Import socket module
import socket
def Main:
# local host IP
host
# Define the port on which you want to connect
port
s socket.socketsocketAFINET,socket.SOCKSTREAM
# connect to server on local computer
sconnecthostport
# message you send to server
message "shaurya says geeksforgeeks"
while True:
# message sent to server
ssendmessageencodeascii
# message received from server
data srecv
# print the received message
# here it would be a reverse of sent message
printReceived from the server :strdatadecodeascii
# ask the client whether he wants to continue
ans input
Do you want to continueyn :
if ans y:
continue
else:
break
# close the connection
sclose
if namemain:
Main
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
