[Solved]Tcp Sockets Programming Python Need Help Debugging Client Server Code Able Establish Conne Q37172208
TCP SOCKETS PROGRAMMING IN PYTHON.
I need some help debugging the client and server code. i am ableto establish connection with server but i am not able to get replyback from the server. possibly what i am sending to server isntreaching and server isnt sending back.
“Remote Calculator” application that works as follows:The client program inputs two integers and an arithmetic operation(‘*’,’/’,’%’,’+’,’-‘) from the user and sends these three values tothe server side. The server does the binary operation on the twointegers and sends backs the result of the operation to the client.The client displays the result to the user.
Below is the client and server code. DEBUG AND SHOW ME WHERE THEBUGs are AND ALSO INCLUDE SCREENSHOTS OF THE APPLICATION WORKINGWELL IN PYTHON SHELL. THANKS IN ADVANCE
server.py :
import socket
HOST = ‘127.0.0.1’
PORT = 65432
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen()
condition = True
while condition:
ans = None
conn, addr = s.accept()
data = conn.recv(1024)
if not data:
break
else:
#print(data.decode(‘utf-8’))
condition = False # use some if clause to modify this to changewhen the server connection closes.
num1, num2, oper = str(data.decode(‘utf-8’)).split(” “)
#print(num1,num2,oper)
if(oper == ‘+’):
ans = int(num1) + int(num2)
elif(oper == ‘-‘):
ans = int(num1) – int(num2)
elif(oper == ‘*’):
ans = int(num1) * int(num2)
elif(oper == ‘/’):
ans = int(num1) / int(num2)
elif(oper == ‘%’):
ans = int(num1) % int(num2)
else:
ans = “Sent operation is not valid”
conn.sendall(str(ans).encode(‘utf-8’))
s.close()
client.py
import socket
HOST = ‘127.0.0.1’
PORT = 65432
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
print(“Give me two number and an operation”)
num1 = int(input(“Number 1:”))
num2 = int(input(“Number 2:”))
oper = input(“Operation :”)
ques = str(num1) + ” ” + str(num2) + ” ” + str(oper)
s.sendall(ques.encode(‘utf-8’))
ans = s.recv(1024)
print(‘nThe answer is ‘, ans.decode(‘utf-8’))
Expert Answer
Answer to TCP SOCKETS PROGRAMMING IN PYTHON. I need some help debugging the client and server code. i am able to establish connect… . . .
OR

