Note that there are some explanatory texts on larger screens.

plurals
  1. POpython Tornado websockets how to send message every X seconds?
    primarykey
    data
    text
    <p>I am trying to cobble together a test which allows websockets clients to connect to a Tornado server and I want the Tornado server to send out a message to all clients every X seconds.</p> <p>The reason I am doing this is because wbesockets connections are being silently dropped somewhere and I am wondering of periodic "pings" sent by the websockets server will maintain the connection.</p> <p>I'm afraid it's a pretty noobish question and the code below is rather a mess. I just don't have my head wrapped around Tornado and scope enough to make it work.</p> <pre><code>import tornado.httpserver import tornado.websocket import tornado.ioloop import tornado.web import tornado.gen import time from tornado import gen class WSHandler(tornado.websocket.WebSocketHandler): def open(self): print 'http://mailapp.crowdwave.com/girlthumb.jpg' self.write_message("http://www.example.com/girlthumb.jpg") def on_message(self, message): print 'Incoming message:', message self.write_message("http://www.example.com/girlthumb.jpg") def on_close(self): print 'Connection was closed...' @gen.engine def f(): yield gen.Task(tornado.ioloop.IOLoop.instance().add_timeout, time.time() + 8) self.write_message("http://www.example.com/x.png") print 'x' @gen.engine def g(): yield gen.Task(tornado.ioloop.IOLoop.instance().add_timeout, time.time() + 4) self.write_message("http://www.example.com/y.jpg") print 'y' application = tornado.web.Application([ (r'/ws', WSHandler), ]) if __name__ == "__main__": tornado.ioloop.IOLoop.instance().add_callback(f) tornado.ioloop.IOLoop.instance().add_callback(g) http_server = tornado.httpserver.HTTPServer(application) http_server.listen(8888) tornado.ioloop.IOLoop.instance().start() </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload