Please use Python programming language to write a client program and a server program, so that these two programs communicate through a TCP connection based on the following scenario:
CLIENT.py
from socket import *
s=socket(AF_INET, SOCK_STREAM)
s.connect(("localhost",8000))
r=s.recv(1024)
a=input(r)
s.send(bytes(str(a), 'utf8'))
area=s.recv(1024)
AREA=area.decode('utf8')
print("Area of Circle is:",AREA)
---------------------------------------------------------------------------------------
SERVER.py
from socket import *
s=socket(AF_INET, SOCK_STREAM)
s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
s.bind(("", 8000))
s.listen(5)
c, a=s.accept()
c.send(bytes("Enter Radius",'utf8'))
m=c.recv(1024)
R=m.decode('utf8')
radi=int(R)
area=radi*radi*3.14
c.send(bytes(str(area),'utf8'))
Instructions-
1-First run the server.py (I did using command prompt).
2-Then run client.py. (usiing command prompt)
3-Screenshot is shared of rummimg code.
4-If getting an error because of ports than change ports.
Get Answers For Free
Most questions answered within 1 hours.