Skip to content

Instantly share code, notes, and snippets.

@taotetek
Created February 5, 2011 19:10
Show Gist options
  • Save taotetek/812693 to your computer and use it in GitHub Desktop.
Save taotetek/812693 to your computer and use it in GitHub Desktop.
import eventlet
from eventlet.green import socket
import zmq
import sys
PORT=3001
def read_socket(writer, reader):
line = reader.readline()
while line:
sys.stdout.write(line)
sys.stdout.flush()
writer.send(line)
line = reader.readline()
if __name__ == '__main__':
try:
server = eventlet.listen(('127.0.0.1', 7000))
while True:
new_connection, address = server.accept()
new_zmq_context = zmq.Context()
new_zmq_push_socket = new_zmq_context.socket(zmq.PUSH)
new_zmq_push_socket.connect("tcp://127.0.0.1:5558")
eventlet.spawn_n(read_socket, new_zmq_push_socket, new_connection.makefile('r'))
except (KeyboardInterrupt, SystemExit):
print "bye"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment