from socket import * serverName = 'localhost' serverPort = 12000 clientSocket = socket(AF_INET, SOCK_DGRAM) clientSocket.settimeout(0.5) # Give up after a half second. message = input('Input lowercase sentence:').encode('ascii') clientSocket.sendto(message, (serverName, serverPort)) modifiedMessage, serverAddress = clientSocket.recvfrom(2048) print(modifiedMessage.decode('ascii')) clientSocket.close() # Suggestions for further improvement: # (1) Catch the timeout exception and retry a limited number of times. # (2) Start with a small timeout and increase it each retry.