Client_side(TCP)

TCPclient_capitalize.py

from socket import *

serverName = '~~~.~~~.123.171'

serverPort = 12000


while 1: 

clientSocket = socket(AF_INET, SOCK_STREAM)

clientSocket.connect((serverName,serverPort))

sentence = raw_input('Input lowercase sentence:')

clientSocket.send(sentence)

modifiedSentence = clientSocket.recv(1024)

print 'From Server:', modifiedSentence

clientSocket.close()


Server_side(TCP)

socket_capitalize.py

from socket import *         #Import socket module

serverPort = 12000          

serverSocket = socket(AF_INET, SOCK_STREAM)    #Create TCP socket with 'SOCK_STREAM'

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

serverSocket.listen(1)                                         #Listen for TCP connection with max num of queued of conn of at least 1

print 'The sever is ready to receive'


while 1:

connectionSocket, addr = serverSocket.accept()     #Create socket called connectionSocket when client knocks

sentence = connectionSocket.recv(1024)               #Store message in 'sentence'

capitalizedSentence = sentence.upper()                 #Capitalize message and store

connectionSocket.send(capitalizedSentence)         #Reply back to client with 'capitalizedSentence'

connectionSocket.close()







































WRITTEN BY
서상호

,