Develop a client and server model Socket Program using pytho

Develop a client and server model (Socket Program) using python to add two number givens by client. Server should return answer to client in following format:
Addition is [answer].

Kindly help me on this for both client and server.

Solution

#!/usr/bin/python           # This is server.py file

import socket               # Import socket module

s = socket.socket()         # Create a socket object

host = socket.gethostname() # Get local machine name

port = 12345                # Reserve a port for your service.

s.bind((host, port))        # Bind to the port

s.listen(5)                 # Now wait for client connection.

while True:

   c, addr = s.accept()     # Establish connection with client.

   print \'Got connection from\', addr
   print \'Program to add two numbers\'
  
   a=c.recv(1024)

   b=c.recv(1024)

   print ‘sever received’

   sum = a+b

print ‘Addition is’ , sum

   c.close()                # Close the connection

********************************

#!/usr/bin/python           # This is client.py file

import socket               # Import socket module

s = socket.socket()         # Create a socket object

host = socket.gethostname() # Get local machine name

port = 12345                # Reserve a port for your service.

s.connect((host, port))

print s.recv(1024)

a = int(raw_input(“Enter 1st number”))
s.send(str(a))

b = int(raw_input(“Enter 2nd number”))
s.send(str(b))

s.close()                   # Close the socket when done

Develop a client and server model (Socket Program) using python to add two number givens by client. Server should return answer to client in following format: A
Develop a client and server model (Socket Program) using python to add two number givens by client. Server should return answer to client in following format: A

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site