我有一个远程传感器,通过长时间生活的websocket会话连接到我的Tornado服务器:
class WSHandler(tornado.websocket.WebSocketHandler):
def open(self):
puts('New connection was opened.')
self.write_message('Connection open.')
def on_message(self, message):
print 'Incoming message:', message
self.write_message(message)
def on_close(self):
print 'Connection was closed...'
sensor_application = Application([ (r'/ws', WSHandler)])
然后我有另一个基于web的gui的应用程序:
class HelloHandler(RequestHandler):
def get(self):
self.render('index.html')
client_application = Application([ (r'/', HelloHandler)])
并且这两个应用程序都在不同的端口上运行。
ws_server = tornado.httpserver.HTTPServer(sensor_application)
ws_server.listen(8889)
http_server = tornado.httpserver.HTTPServer(client_application)
http_server.listen(8888)
tornado.ioloop.IOLoop.instance().start()
说我的传感器测量温度。我如何在HelloHandler中实现一个页面,该页面可以在WSHandler中调用websocket方法并向基于Web的客户端显示温度。