Skip to content

Instantly share code, notes, and snippets.

@ayuthmang
Last active December 6, 2017 16:53
Show Gist options
  • Save ayuthmang/98e65c2a007c24984df8d3e706ee3ff7 to your computer and use it in GitHub Desktop.
Save ayuthmang/98e65c2a007c24984df8d3e706ee3ff7 to your computer and use it in GitHub Desktop.
TCPClient-TCPServer from Computer Networking A Top-Down Approach 6th Edition
from socket import *
serverName = '127.0.0.1'
serverPort = 12000
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()
from socket import *
serverPort = 12000
serverSocket = socket(AF_INET, SOCK_STREAM)
serverSocket.bind(('127.0.0.1', serverPort))
serverSocket.listen(1)
print 'The server is ready to receive'
while 1:
connectionSocket, addr = serverSocket.accept()
sentence = connectionSocket.recv(1024)
capitalizedSentence = sentence.upper()
connectionSocket.send(capitalizedSentence)
connectionSocket.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment