Skip to content

Instantly share code, notes, and snippets.

@bivald
Created May 30, 2012 09:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bivald/2834862 to your computer and use it in GitHub Desktop.
Save bivald/2834862 to your computer and use it in GitHub Desktop.
Eventlet echo server
#! /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