APP Assignment
APP Assignment
ABHISESHA
KUMAARA
REG NO :
RA2211026010487
SECTION: Z2
Week 12- Tutorial Assignment
Implement Python program - TCP/UDP program using Sockets
PROGRAMS
1. Develop a simple Python program of TCP, client that can connect to
the server and client can send a "Hello, Server!" message to the
server.
#PROGRAM
import
socket
1. Develop a Python program that allows the TCP client to send a list
of numbers to the server. The server should calculate and return the
sum of the numbers to the client.
#PROGRAM
import socket
while True:
# Accept a client connection
client_socket, client_address = server_socket.accept()
print("Connected to:", client_address)
while True:
# Receive data from the client
data, client_address = server_socket.recvfrom(1024)
import socket
1. Create a Python UDP client that sends a random number to the UDP server. The
server should check if the number is even or odd and send the result back to the client.
#UDP Server Code :
import socket import
random
while True:
import socket
import random
1. Extend the UDP server to respond to the client's "UDP Message" packet with an
acknowledgment message. Provide the code for the server-client interaction.
while True:
# Receive data from the client
data, client_address = server_socket.recvfrom(1024)
received_message = data.decode('utf-8')
else:
print(f"Received an unexpected message:
'{received_message}' from {client_address}")
#Server Code
import socket
while True:
# Accept a client connection
client_socket, client_address = server_socket.accept()
print("Connected to:", client_address)
1. Create a TCP server that echoes back any message it receives from a client. Develop
a Python client to send messages to the server and display the echoed response.
while True:
# Accept a client connection
client_socket, client_address = server_socket.accept()
print("Connected to:", client_address)
if not data:
break # Exit the loop if no data received
1. Develop a simple Python program that sends a small text file from a TCP
client to a TCP server. Confirm that the file is received and saved correctly.
#SERVER
import socket
while True:
# Accept a client connection
client_socket, client_address = server_socket.accept()
print("Connected to:", client_address)
if not data:
break # Exit the loop if no data received
while True:
if message == 'exit':
break
while True:
if message == 'exit':
break
while True: