string 이든 number 이든 입력하면,
server에서 순서를 reverse 해서 다시 client 에게 보내주는 프로그램이다.
Client_side
UDPclient_backward.py
from socket import * serverName = '~~~.~~~.123.171' serverPort = 12002 while 1: clientSocket = socket(AF_INET, SOCK_DGRAM) message = raw_input('Input a word or sentence to reverse:') clientSocket.sendto(message,(serverName, serverPort)) modifiedMessage, serverAddress = clientSocket.recvfrom(2048) print modifiedMessage clientSocket.close() |
Server_side
UDPserver_backward.py
from socket import * # Import socket module serverPort = 12002 # 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 12002 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[::-1] # Reverse the order of message and store in modifiedMessage serverSocket.sendto(modifiedMessage, clientAddress) # Reply to client with modifiedMessage
|
WRITTEN BY