0% found this document useful (0 votes)
6 views3 pages

TCP and UDP Socket Programming in Python

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

TCP and UDP Socket Programming in Python

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
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

**********************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=[Link](socket.AF_INET , socket.SOCK_STREAM)
[Link](([Link](),1028))
[Link](10)
while True:
clt,adr=[Link]()
print(f"Connection to {adr} is established.")
[Link](bytes("TCP Socket programming in python ","utf-8"))
[Link]()

Client:
import socket
s=[Link](socket.AF_INET,socket.SOCK_STREAM)
[Link](([Link](),1028))
m=[Link](100)
print([Link]("utf-8"))

Output:

Server:
Client:

UDP Socket Programming:

Program Code:

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

Client:
import socket
s=[Link](socket.AF_INET,socket.SOCK_DGRAM)
host=[Link]()
port=1200
[Link]((host,port))
msg="UDP Socket programming in python. "
print("UDP Target IP: ",host)
print("UDP Target Port: ",port)
[Link](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