Created
May 30, 2012 09:10
-
-
Save bivald/2834862 to your computer and use it in GitHub Desktop.
Eventlet echo server
This file contains 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 characters
#! /usr/bin/env python | |
""" | |
Copied from http://eventlet.net/doc/examples.html#echo-server | |
Simple server that listens on port 8014 and echos back every input to | |
the client. To try out the server, start it up by running this file. | |
""" | |
import eventlet | |
def handle(fd): | |
print "client connected" | |
while True: | |
# pass through every non-eof line | |
x = fd.readline() | |
if not x: break | |
fd.write(x) | |
fd.flush() | |
print "echoed", x, | |
print "client disconnected" | |
print "echo server socket listening on port 8014" | |
server = eventlet.listen(('0.0.0.0', 8014)) | |
pool = eventlet.GreenPool() | |
while True: | |
try: | |
new_sock, address = server.accept() | |
print "accepted", address | |
pool.spawn_n(handle, new_sock.makefile('rw')) | |
except (SystemExit, KeyboardInterrupt): | |
break |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment