예제 #1
0
def main():
    # Create multiplexer
    # get([default connection],**[channels = other connections])
    router = MultiplexConnection.get(DefConnection, ann=AConnection, bob=AConnection, carl=AConnection)
    # Not declared channels connect default connection others connect their connections
    # Register multiplexer
    EchoRouter = sockjs.tornado.SockJSRouter(router, "/echo")
    return EchoRouter
예제 #2
0
from tornado import web
from tornado.web import URLSpec as url
from sockjs.tornado import SockJSRouter

from settings import settings
from utils import include
from multiplex import MultiplexConnection
from apps.main.views import groupConnection, privateConnection
# Create multiplexer
router = MultiplexConnection.get(group=groupConnection, private=privateConnection)
print "router : ", router
# Register multiplexer
EchoRouter = SockJSRouter(router, '/chat')
# print "echorouter.ursl : ",EchoRouter.urls


urls = [
    url(r"/static/(.*)", web.StaticFileHandler, {"path": settings.get('static_path')}),
]
urls += include(r"/", "apps.main.urls")

urls = urls + EchoRouter.urls



예제 #3
0
파일: server.py 프로젝트: vaxXxa/gomoku
    tornado.options.define("address", default="localhost", help="Run on host", type=str)
    tornado.options.parse_command_line()

    # Create multiplexer
    channels = {
        "username_choice": connections.UsernameChoiceConnection,
        "stats": connections.StatsConnection,
        "note": connections.NoteConnection,
        "games_list": connections.GamesListConnection,
        "games_join": connections.GamesJoinConnection,
        "game_create": connections.GameCreateConnection,
        "game_action": connections.GameActionConnection,
        "game_finish": connections.GameFinishConnection,
    }

    router = MultiplexConnection.get(**channels)

    # Register multiplexer
    MainSocketRouter = SockJSRouter(router, "/socket")

    # Create application
    app = tornado.web.Application(
        [(r"/", IndexHandler), (r"/static/(.*)", tornado.web.StaticFileHandler, {"path": rel("static")})]
        + MainSocketRouter.urls
    )
    app.listen(tornado.options.options.port, address=tornado.options.options.address)

    io_loop = tornado.ioloop.IOLoop.instance()
    tornado.autoreload.start(io_loop)
    io_loop.start()
예제 #4
0
        (r'/css/(.*)', tornado.web.StaticFileHandler, {
            'path': os.path.join(os.path.dirname(__file__), 'css')
        }),
        (r'/fonts/(.*)', tornado.web.StaticFileHandler, {
            'path': os.path.join(os.path.dirname(__file__), 'fonts')
        }),
    ]

    ListenerRouter = SockJSRouter(ListenerConnection, '/listener')
    handlers.extend(ListenerRouter.urls)

    BodyRouter = SockJSRouter(BodyConnection, '/body')
    handlers.extend(BodyRouter.urls)

    # Create multiplexer
    router = MultiplexConnection.get(objClass=HijackConnection)

    # Register multiplexer
    HijackRouter = SockJSRouter(router, '/hijack')
    handlers.extend(HijackRouter.urls)

    options = OptionParser()
    options.define("port",
                   default=8002,
                   help="run on the given port",
                   type=int)
    options.define("proxyport",
                   default=8989,
                   help="port the proxy is running on",
                   type=int)
    options.define("proxyhost",
예제 #5
0
        (r"/docsettings", DocSettingsHandler),
        (r"/docsettings/add", DocSettingsAddHandler),
        (r"/docsettings/(?P<ident>[^\/]+)", DocSettingsEditHandler),
        (r'/static/(.*)', tornado.web.StaticFileHandler, {'path': os.path.join(os.path.dirname(__file__), 'static')}),
        (r'/css/(.*)', tornado.web.StaticFileHandler, {'path': os.path.join(os.path.dirname(__file__), 'css')}),
        (r'/fonts/(.*)', tornado.web.StaticFileHandler, {'path': os.path.join(os.path.dirname(__file__), 'fonts')}),
    ]
        
    ListenerRouter = SockJSRouter(ListenerConnection, '/listener')
    handlers.extend(ListenerRouter.urls)

    BodyRouter = SockJSRouter(BodyConnection, '/body')
    handlers.extend(BodyRouter.urls)

    # Create multiplexer
    router = MultiplexConnection.get(objClass=HijackConnection)

    # Register multiplexer
    HijackRouter = SockJSRouter(router, '/hijack')
    handlers.extend(HijackRouter.urls)

    options = OptionParser()
    options.define("port", default=8002, help="run on the given port", type=int)
    options.define("proxyport", default=8989, help="port the proxy is running on", type=int)
    options.define("proxyhost", default=None, help="host the proxy is running on", type=str)
    options.define("mongourl", default="localhost:27017", help="mongodb url", type=str)

    options.parse_command_line()

    db = motor.MotorClient('mongodb://'+options.mongourl, tz_aware=True)
    
예제 #6
0
    def on_open(self, info):
        self.send('Bob doesn\'t agree.')

    def on_message(self, message):
        self.send('Bob says no to: ' + message)


class CarlConnection(SockJSConnection):
    def on_open(self, info):
        self.send('Carl says goodbye!')

        self.close()

if __name__ == "__main__":
    import logging
    logging.getLogger().setLevel(logging.DEBUG)

    # Create multiplexer
    router = MultiplexConnection.get(ann=AnnConnection, bob=BobConnection, carl=CarlConnection)

    # Register multiplexer
    EchoRouter = SockJSRouter(router, '/echo')

    # Create application
    app = tornado.web.Application(
            [(r"/", IndexHandler), (r"/multiplex.js", MultiplexStaticHandler)] + EchoRouter.urls
    )
    app.listen(9999)

    tornado.ioloop.IOLoop.instance().start()
예제 #7
0
                           type=str)
    tornado.options.parse_command_line()

    # Create multiplexer
    channels = {
        'username_choice': connections.UsernameChoiceConnection,
        'stats': connections.StatsConnection,
        'note': connections.NoteConnection,
        'games_list': connections.GamesListConnection,
        'games_join': connections.GamesJoinConnection,
        'game_create': connections.GameCreateConnection,
        'game_action': connections.GameActionConnection,
        'game_finish': connections.GameFinishConnection
    }

    router = MultiplexConnection.get(**channels)

    # Register multiplexer
    MainSocketRouter = SockJSRouter(router, '/socket')

    # Create application
    app = tornado.web.Application([
        (r'/', IndexHandler),
        (
            r'/static/(.*)',
            tornado.web.StaticFileHandler,
            {
                'path': rel('static')
            },
        ),
    ] + MainSocketRouter.urls)