(socket, address, io_loop)
A server connection handler that repeats back lines received
    from the client.  The server stops echoing if the client says
    'goodbye'.
A server connection handler that repeats back lines received
    from the client.  The server stops echoing if the client says
    'goodbye'.
A server connection handler that repeats back lines received from the client . The server stops echoing if the client says goodbye .
def echo(socket, address, io_loop):
    """A server connection handler that repeats back lines received
    from the client.  The server stops echoing if the client says
    'goodbye'."""

    stream = IOStream(socket, io_loop=io_loop)

    def write(data, *args):
        print 'S: %r' % data
        stream.write(data, *args)

    def handle(data):
        if data == 'goodbye\n':
            write('See you later.\n', stream.close)
        else:
            write('You said: "%s".\n' % data.strip())
            loop()

    def loop():
        stream.read_until("\n", handle)

    loop()
def echo ( socket , address , io_loop ) : stream = IOStream ( socket , io_loop = io_loop ) def write ( data , * args ) : print 'S: %r' % data stream . write ( data , * args ) def handle ( data ) : if data == 'goodbye\n' : write ( 'See you later.\n' , stream . close ) else : write ( 'You said: "%s".\n' % data . strip ( ) ) loop ( ) def loop ( ) : stream . read_until ( "\n" , handle ) loop ( )