Client_side(TCP)
TCPClient_backward.py
from socket import * serverName = '~~~.~~~.123.171' serverPort = 12010 while 1: clientSocket = socket(AF_INET, SOCK_STREAM) clientSocket.connect((serverName,serverPort)) message = raw_input('Input a word or sentence to reverse:') clientSocket.send(message) reversedSentence = clientSocket.recv(1024) print 'Reversed:', reversedSentence clientSocket.close() |
Server_side(TCP)
socket_backward.py
from socket import * #Import socket module serverPort = 12010 serverSocket = socket(AF_INET,SOCK_STREAM) #Create TCP socket with 'SOCK_STREAM' serverSocket.bind(('',serverPort)) #Assign port number 12010 to the server's socket serverSocket.listen(1) #Listen for TCP connection with max num of queued connection connection of at least 1 print 'The server is ready to receive' while 1: connectionSocket, addr = serverSocket.accept() #Create socket called connectionSocket when client knocks message = connectionSocket.recv(1024) #Store message in 'message' modifiedMessage = message[::-1] #Reverse message and store connectionSocket.send(modifiedMessage) #Reply back to client with 'modifiedMessage' connectionSocket.close()
|
WRITTEN BY
,