-
-
Save reddypdl/2b7848a9f88ccc9f9399 to your computer and use it in GitHub Desktop.
Revisions
-
baijum revised this gist
Jan 21, 2012 . 2 changed files with 31 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,15 @@ import socket HOST, PORT = "localhost", 9999 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect((HOST, PORT)) sock.send("get" + "\n") received = sock.recv(1024) finally: sock.close() print received This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,16 @@ import socket import sys HOST, PORT = "localhost", 9999 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect((HOST, PORT)) sock.send("put %s" % sys.argv[1] + "\n") received = sock.recv(1024) finally: sock.close() print received -
baijum created this gist
Jan 21, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ import Queue import SocketServer node_queue = Queue.LifoQueue() class TCPQueueHandler(SocketServer.BaseRequestHandler): def handle(self): self.data = self.request.recv(1024).strip() if self.data == "get": out = node_queue.get(False) self.request.send(str(out)) elif self.data.startswith("put"): d = self.data.split()[1] node_queue.put(d) if __name__ == "__main__": HOST, PORT = "localhost", 9999 server = SocketServer.TCPServer((HOST, PORT), TCPQueueHandler) server.serve_forever()