Created
January 2, 2012 23:46
-
-
Save mrdaemon/1552666 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
from gevent.server import StreamServer | |
def echo(socket, address): | |
""" Handler for shitty echo server """ | |
print "New connection from %s:%s" % (address) | |
fileobj = socket.makefile() | |
fileobj.write("Welcome to the anus over tcp/ip server!\n\r") | |
fileobj.flush() | |
while True: | |
line = fileobj.readline() | |
if not line: | |
print "Asshole at %s:%s disconnected" % (address) | |
break | |
if line.strip().lower() == 'quit': | |
print "Cheers bye %s:%s, stupid client." % (address) | |
break | |
fileobj.write(line) | |
fileobj.flush() | |
print "echo: %r" % (line) | |
def main(): | |
""" Program entry point """ | |
server = StreamServer(('0.0.0.0', 6000), echo) | |
print "Starting anus server on port 6000" | |
server.serve_forever() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment