baseimage-tutorial-framework/lib/tfw/server/tfw_server.py

30 lines
884 B
Python
Raw Normal View History

# Copyright (C) 2018 Avatao.com Innovative Learning Kft.
# All Rights Reserved. See LICENSE file for details.
from tornado.web import Application
2019-05-27 12:09:13 +00:00
from tfw.networking import EventHandlerConnector
2018-02-23 11:07:30 +00:00
from tfw.config.logs import logging
2018-07-25 13:46:39 +00:00
2019-05-27 12:09:13 +00:00
from .zmq_websocket_proxy import ZMQWebSocketProxy
LOG = logging.getLogger(__name__)
2019-05-26 16:26:33 +00:00
class TFWServer:
2018-04-18 17:44:26 +00:00
"""
This class handles the proxying of messages between the frontend and event handers.
It proxies messages from the "/ws" route to all event handlers subscribed to a ZMQ
SUB socket.
2018-04-18 17:44:26 +00:00
"""
def __init__(self):
self._event_handler_connector = EventHandlerConnector()
self.application = Application([(
r'/ws', ZMQWebSocketProxy, {
'event_handler_connector': self._event_handler_connector,
}
)])
2018-04-10 11:00:56 +00:00
def listen(self, port):
self.application.listen(port)