我需要一个服务器,通过websocket接收来自浏览器的连接 . 像这样的东西
import tornado.web
import tornado.ioloop
import tornado.websocket
from tornado import template
class MainHandler(tornado.web.RequestHandler):
def get(self):
self.render('index.html')
class WebSocket(tornado.websocket.WebSocketHandler):
def check_origin(self, origin):
return True
def open(self):
print("WebSocket opened")
def on_message(self, message):
self.write_message(message)
def on_close(self):
print("WebSocket closed")
class Application(tornado.web.Application):
def __init__(self):
handlers = ((r'/', MainHandler),(r'/websocket/?', WebSocket),
(r'/static/(.*)', tornado.web.StaticFileHandler,
{'path': 'static/'}),)
tornado.web.Application.__init__(self, handlers, debug=True)
if __name__ == '__main__':
application = Application()
application.listen(8888)
tornado.ioloop.IOLoop.instance().start()
收到消息后,应将其传递给RPC-client,将其发送到RabbitMQ并接收响应 . 然后这个响应进入浏览器 . 怎么做?
我想RPC-client应该作为一个单独的进程启动,套接字应该从服务器传递到RPC-client . 但怎么办呢?
也许龙卷风有内在的可能性来做这样的事情 .