def main(url, message='hello, world'):

    class HelloSocket(WebSocket):

        def on_open(self):
            self.ping()
            print '>>', message
            self.write_message(message)

        def on_message(self, data):
            print 'on_message:', data
            msg = raw_input('>> ')
            if msg == 'ping':
                self.ping()
            elif msg == 'die':
                self.close()
            else:
                self.write_message(msg)

        def on_close(self):
            print 'on_close'

        def on_pong(self):
            print 'on_pong'

    ws = HelloSocket(url)
    try:
        ioloop.IOLoop.instance().start()
    except __HOLE__:
        pass
    finally:
        ws.close()
dataset/ETHPy150Open jbalogh/tornado-websocket-client/websocket.py/main