client 에서 입력하는 message 가 서버로 전달되고,

server 에서 입력받은 message를 uppercase(대문자)로 변환하여 다시 client 로 전송하는 프로그램이다. 


Client_side

UDPclient_capitalize.py

from socket import *

serverName = '~~~.~~~.123.171'   # according to intended server IP address 

serverPort = 12001  # arbitrarily chosen port number


while 1: 

    clientSocket = socket(AF_INET, SOCK_DGRAM)        # this creates socket _ SOCK_DGRAM indicates that this is a UDP connection

    message = raw_input('Input lowercase sentence:')     # stores the input into 'message'

    clientSocket.sendto(message,(serverName, serverPort))    

    modifiedMessage, serverAddress = clientSocket.recvfrom(2048)   # 2048 indicates the buffer size       

    print modifiedMessage

    clientSocket.close()                   

 



Server_side

UDPserver_capitalize.py

from socket import *                         # Import socket module

serverPort = 12001                           # Designate port number to be made available

serverSocket = socket(AF_INET, SOCK_DGRAM)   # Create UDP socket with 'SOCK_DGRAM'

serverSocket.bind(('', serverPort))          # Assign port number 12000 to the server's socket             

print "The server is ready to receive"                                   

while 1:                                     # Run never-ending loop because server must be always on 

message, clientAddress = serverSocket.recvfrom(2048)  # Input from client is stored in 'message'

                                                              # ClientAddress is needed to reply back to host 

modifiedMessage = message.upper()                     # Change input in message to uppercase with upper() method

serverSocket.sendto(modifiedMessage, clientAddress)   # Reply back to client with uppercased message


 
















WRITTEN BY
서상호

,