Commit a4b3d1c3 authored by Denis Bilenko's avatar Denis Bilenko

slightly shorten echoserver.py

parent ef280b1b
......@@ -12,10 +12,9 @@ from gevent.server import StreamServer
# this handler will be run for each incoming connection in a dedicated greenlet
def echo(socket, address):
print ('New connection from %s:%s' % address)
socket.sendall('Welcome to the echo server! Type quit to exit.\r\n')
# using a makefile because we want to use readline()
fileobj = socket.makefile()
fileobj.write('Welcome to the echo server! Type quit to exit.\r\n')
fileobj.flush()
while True:
line = fileobj.readline()
if not line:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment