Skip to content

Instantly share code, notes, and snippets.

@reddypdl
Forked from baijum/queueget.py
Last active August 29, 2015 14:16
Show Gist options
  • Select an option

  • Save reddypdl/2b7848a9f88ccc9f9399 to your computer and use it in GitHub Desktop.

Select an option

Save reddypdl/2b7848a9f88ccc9f9399 to your computer and use it in GitHub Desktop.

Revisions

  1. @baijum baijum revised this gist Jan 21, 2012. 2 changed files with 31 additions and 0 deletions.
    15 changes: 15 additions & 0 deletions queueget.py
    Original 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
    16 changes: 16 additions & 0 deletions queuepush.py
    Original 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
  2. @baijum baijum created this gist Jan 21, 2012.
    20 changes: 20 additions & 0 deletions tcpqueue.py
    Original 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()