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.
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
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
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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment