Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Plz use PYTHON to ANSWER THIS QUESTION Description Write both the CLIENT and SER

ID: 3872831 • Letter: P

Question

Plz use PYTHON to ANSWER THIS QUESTION

Description

Write both the CLIENT and SERVER-side code using PYTHON.

In this assignment, you will design and implement a service to evaluate arithmetic expressions, as well as a testing client.

Protocol Spec

Request format

1. Number of expressions to evaluate. [2 bytes]

2. Length of 1st expression in bytes. [2 bytes]

3. String representation of 1st expression.

4. Length of 2nd expression in bytes. [2 bytes]

5. String representation of 2nd expression.

6. …

7. Length of nth expression in bytes. [2 bytes]

8. String representation of nth expression.

Response format

1. Number of answers. [2 bytes]

2. Length of 1st answer in bytes. [2 bytes]

3. String representation of 1st answer.

4. Length of 2nd answer in bytes. [2 bytes]

5. String representation of 2nd answer.

6. …

7. Length of nth answer in bytes. [2 bytes]

8. String representation of nth answer.

Requirements

1. All numbers in expressions are integers.

2. Required to handle ‘+’, ‘-’, ‘*’, ‘/’. Optional for parenthesis.

3. Don’t use ‘eval’ in Python.

4. Use TCP as transport layer protocol.

5. Implement both server and client (server needs to be multithreaded).

6. Limit your buffer size for send/recv API to 16 bytes. (So you need to have axillary

function to call recv multiple times to make sure entire request/response is received).

Example request 2 4 "3+12" 2 bytes 2 bytes 4 bytes 2 bytes 6 bytes Example response 2 2 "15" 1 5 2 bytes 2 bytes 2 bytes 2 bytes byte

Explanation / Answer

ANSWER::

# server.py
import socket
import time
serversocket = socket.socket(
socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostname()
port = 9999
serversocket.bind((host, port))   
serversocket.listen(5)
clientsocket,addr = serversocket.accept()   
print("Got a connection from %s" % str(addr))
currentTime = time.ctime(time.time()) + " "
clientsocket.send(currentTime.encode('ascii'))
clientsocket.close()

# Client.py
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
host = socket.gethostname()
port = 9999
s.connect((host, port))   
tm = s.recv(1024)
s.close()
print("The time got from the server is %s" % tm.decode('ascii'))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote