0% found this document useful (0 votes)
36 views

NAME - ANIKET.K - I2-39 Experiment No. 12 Aim: TCP Socket Programming: Program Code

The document describes experiments with TCP and UDP sockets in Python. It includes Python code for a TCP server and client that establish a connection and send a message. It also includes Python code for a UDP server that receives messages and a UDP client that sends a message to the server. The aim is to understand socket programming in Python and the conclusion confirms TCP and UDP socket programs were successfully executed.

Uploaded by

aniket kasturi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

NAME - ANIKET.K - I2-39 Experiment No. 12 Aim: TCP Socket Programming: Program Code

The document describes experiments with TCP and UDP sockets in Python. It includes Python code for a TCP server and client that establish a connection and send a message. It also includes Python code for a UDP server that receives messages and a UDP client that sends a message to the server. The aim is to understand socket programming in Python and the conclusion confirms TCP and UDP socket programs were successfully executed.

Uploaded by

aniket kasturi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

**********************NAME -ANIKET.

K -I2-39**************

Experiment No. 12

Aim: Write python programs to understand TCP and UDP Sockets in Python.

TCP Socket Programming:

Program Code:

Server:
import socket
s=socket.socket(socket.AF_INET , socket.SOCK_STREAM)
s.bind((socket.gethostname(),1028))
s.listen(10)
while True:
clt,adr=s.accept()
print(f"Connection to {adr} is established.")
clt.send(bytes("TCP Socket programming in python ","utf-8"))
clt.close()

Client:
import socket
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((socket.gethostname(),1028))
m=s.recv(100)
print(m.decode("utf-8"))

Output:

Server:
Client:

UDP Socket Programming:

Program Code:

Server:
import socket
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
s.bind((socket.gethostname(),1200))
while True:
clt,adr=s.recvfrom(100)
print(f"Received Message : {clt} from {adr}")

Client:
import socket
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
host=socket.gethostname()
port=1200
s.connect((host,port))
msg="UDP Socket programming in python. "
print("UDP Target IP: ",host)
print("UDP Target Port: ",port)
s.sendto(bytes(msg,"utf-8"),(host,port))
Output:

Server:

Client:

Conclusion: Hence we have successfully executed programs for TCP and UDP
Socket.

Lab Outcome: Design and develop Client Server network applications using
Python.

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

You might also like