Professional Documents
Culture Documents
TE Division B
Explanation : Socket
programming is a way of connecting two nodes on a network to
communicate with each other. One socket(node) listens on a particular port at an
IP, while the other socket reaches out to the other to form a connection. The
server forms the listener socket while the client reaches out to the server.
They are the real backbones behind web browsing. In simpler terms, there is a
server and a client.
Socket programming is started by importing the socket library and making a
simple socket.
Code :
import socket
host='127.0.0.1'
port=9000
s=socket.socket()
s.bind((host,port))
s.listen(1)
c,addr=s.accept()
print("Client Connected...")
while True:
data1=c.recv(1024)
if not data1:
break
print("From Client:",str(data1.decode()))
data2=input("Enter message=")
c.send(data2.encode())
c.close()
import socket
host='127.0.0.1'
port=9000
s=socket.socket()
s.connect((host,port))
s1=input("Enter message=")
while s1!='EXIT':
s.send(s1.encode())
s2=s.recv(1024)
s2=s2.decode()
print("From Server:",s2)
s1=input("Enter message=")
c.close()
End Result:
Conclusion: