私はWebSocketをクライアントがトルネードサーバーに接続することができますし、私はトルネードサーバーはすべてのクライアントにX秒ごとにメッセージを送信するテストを一緒に考え出すしようとしています。のpythonトルネードはX秒ごとにメッセージを送信する方法WebSocketを?
wbesockets接続が黙ってどこかにドロップされていると私はWebSocketをサーバ接続を維持することにより、送信される定期的な「ピング」と疑問に思っているので、私はこれをやっている理由があります。
私はそれはかなりnoobish質問だと以下のコードはかなり混乱で怖いです。私はちょうど私の頭はトルネードとそれを動作させるのに十分な範囲に巻き付けていません。
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()