Пример #1
0
import tornadio2
from tornadio2.server import SocketServer
import tornado
from tornado.web import Application
from boards import BoardsController

boards_controller = BoardsController()


# MyConnection Class
class MyConnection(tornadio2.SocketConnection):
    def on_message(self, message):
        boards_controller.on_message(self, message)

    def on_close(self):
        boards_controller.unregister(self)


class WebSocketsServer:
    def __init__(self, uri, port):
        # Creating a Tornadio2 server for the connection
        MyRouter = tornadio2.TornadioRouter(MyConnection)

        application = Application(MyRouter.urls, socket_io_port=port)
        self.http_server = SocketServer(application,
                                        auto_start=False,
                                        xheaders=True)

    # Start Tornadio2 server
    def start(self):
        io_loop = tornado.ioloop.IOLoop.instance()
Пример #2
0
 def setUp(self):
     self.boards_controller = BoardsController()