You are on page 1of 4

DEPARTMENT OF COMPUTER ENGINEERING

Computer Network Lab


Semester T.E. Semester V – Computer Engineering

Subject Computer Network

Subject Professor In- Prof. Amit Aylani


charge

Assisting Teachers Prof. Amit Aylani

Laboratory Lab number

Student Name Pratik tayade

Roll Number 20102B0004

TE Division B

Title: Socket programming for TCP and UDP

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 :

❖ Program Code for Server

import socket

Title Roll No:


DEPARTMENT OF COMPUTER ENGINEERING
Computer Network Lab

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()

❖ Program Code for Client

import socket
host='127.0.0.1'

Title Roll No:


DEPARTMENT OF COMPUTER ENGINEERING
Computer Network Lab

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:

Title Roll No:


DEPARTMENT OF COMPUTER ENGINEERING
Computer Network Lab

Conclusion:

Socket programming for TCP and UDP is implemented.

Title Roll No:

You might also like