Skip to content

Instantly share code, notes, and snippets.

@myles
Created November 29, 2010 20:34
Show Gist options
  • Save myles/720559 to your computer and use it in GitHub Desktop.
Save myles/720559 to your computer and use it in GitHub Desktop.
import sys
import socket
HOST, PORT = "127.0.0.1", 9999
data = " ".join(sys.argv[1:])
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((HOST, PORT))
sock.send(data + "\n")
received = sock.recv(1024)
sock.close()
print "Sent: %s" % data
print "Received: %s" % received
import SocketServer
class TCPHandler(SocketServer.BaseRequestHandler):
def handle(self):
self.data = self.request.recv(1024).strip()
print "%s wrote: " % self.client_address[0]
print self.data
self.request.send(self.data.upper())
if __name__ == "__main__":
HOST, PORT = "127.0.0.1", 9999
server = SocketServer.TCPServer((HOST, PORT), TCPHandler)
server.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment