Question: Task 1 : UDP Socket Programming Objective: Create a client - server application using UDP sockets in Python where the client sends a sentence to

Task 1: UDP Socket Programming
Objective:
Create a client-server application using UDP sockets in Python where the client sends a sentence to the server, and the server returns the sentence with the order of words reversed.
Requirements:
UDP Client:
Create a UDP socket.
Get a sentence as input from the user.
Send the sentence to the server.
Receive the reversed sentence from the server and print it.
UDP Server:
Create a UDP socket and bind it to a specific IP and port.
Wait for a message from the client.
Upon receiving a sentence, reverse the order of words in the sentence.
Send the reversed sentence back to the client.
udpclient.py
from socket import *
serverName ='10.142.12.205'
serverPort =12000
clientSocket = socket(AF_INET, SOCK_DGRAM)
message = input('Input lowercase sentence:')
clientSocket.sendto(message.encode(),(serverName, serverPort))
modifiedMessage, serverAddress = clientSocket.recvfrom(2048)
print(modifiedMessage.decode())
clientSocket.close()
udpserver.py
from socket import *
serverPort =12000
serverSocket = socket(AF_INET, SOCK_DGRAM)
serverSocket.bind(('', serverPort))
print("The server is ready to receive")
while True:
message, clientAddress = serverSocket.recvfrom(2048)
modifiedMessage = message.decode().upper()
serverSocket.sendto(modifiedMessage.encode(),
clientAddress)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Accounting Questions!