X-Git-Url: https://review.fuel-infra.org/gitweb?a=blobdiff_plain;f=eventlet%2Fexamples%2Fchat_server.py;fp=eventlet%2Fexamples%2Fchat_server.py;h=0000000000000000000000000000000000000000;hb=358bd9258c2b6d2ee74de4dfd07a5123107abad4;hp=77f09245e7a3cced4cc9edce4c00fee4a9035874;hpb=376ff3bfe7071cc0793184a378c4e74508fb0d97;p=packages%2Ftrusty%2Fpython-eventlet.git diff --git a/eventlet/examples/chat_server.py b/eventlet/examples/chat_server.py deleted file mode 100644 index 77f0924..0000000 --- a/eventlet/examples/chat_server.py +++ /dev/null @@ -1,38 +0,0 @@ -import eventlet -from eventlet.green import socket - -PORT = 3001 -participants = set() - - -def read_chat_forever(writer, reader): - line = reader.readline() - while line: - print("Chat:", line.strip()) - for p in participants: - try: - if p is not writer: # Don't echo - p.write(line) - p.flush() - except socket.error as e: - # ignore broken pipes, they just mean the participant - # closed its connection already - if e[0] != 32: - raise - line = reader.readline() - participants.remove(writer) - print("Participant left chat.") - -try: - print("ChatServer starting up on port %s" % PORT) - server = eventlet.listen(('0.0.0.0', PORT)) - while True: - new_connection, address = server.accept() - print("Participant joined chat.") - new_writer = new_connection.makefile('w') - participants.add(new_writer) - eventlet.spawn_n(read_chat_forever, - new_writer, - new_connection.makefile('r')) -except (KeyboardInterrupt, SystemExit): - print("ChatServer exiting.")