# this handler will be run for each incoming connection in a dedicated greenlet
def echo(socket, address):
- print 'New connection from %s:%s' % address
+ print 'New connection from %s:%s' % address
# 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')
line = fileobj.readline()
- print "client disconnected"
+ print "client disconnected"
if line.strip().lower() == 'quit':
- print "echoed", repr(line)
+ print ("echoed %r" % line)
if __name__ == '__main__':
server = StreamServer(('0.0.0.0', 6000), echo)
# to start the server asynchronously, use its start() method;
# we use blocking serve_forever() here because we have no other jobs
- print 'Starting echo server on port 6000'
+ print 'Starting echo server on port 6000'