Esempio n. 1
0
def start_server(config):
    log.startLogging(sys.stdout)
    router_factory = wamp.RouterFactory()
    session_factory = wamp.RouterSessionFactory(router_factory)
    component_config = types.ComponentConfig(realm=config['realm'])
    component_session = MindwaveComponent(component_config)
    component_session.app_config = config
    session_factory.add(component_session)
    transport_factory = websocket.WampWebSocketServerFactory(session_factory,
                                                             debug=False,
                                                             debug_wamp=False)
    server = serverFromString(reactor, config['server_string'])
    server.listen(transport_factory)
    reactor.run()
Esempio n. 2
0
def get_wamp_service(config):
    debug = config.get("websocket", "debug") == "true"
    client.load_config(config)

    router_factory = wamp.RouterFactory()
    session_factory = wamp.RouterSessionFactory(router_factory)
    component_config = types.ComponentConfig(realm="anonymous")
    session_factory.add(client.DocumentSession(component_config))

    transport_factory = websocket.WampWebSocketServerFactory(session_factory,
                                                             debug=debug,
                                                             debug_wamp=debug)

    server = internet.TCPServer(int(config.get("websocket", "port")),
                                transport_factory,
                                interface=config.get("websocket", "interface"))

    return server
Esempio n. 3
0
    def onJoin(self, details):
        # regs = []
        yield self.register(rpc_bdata, u'ru.bustime.rpc_bdata')
        yield self.register(rpc_passenger, u'ru.bustime.rpc_passenger')
        # mobile support only
        yield self.register(rpc_bootstrap_amounts,
                            u'ru.bustime.rpc_bootstrap_amounts')
        yield self.register(rpc_tcard, u'ru.bustime.rpc_tcard')
        yield self.register(rpc_stop_ids, u'ru.bustime.rpc_stop_ids')


def accept(offers):
    for offer in offers:
        if isinstance(offer, PerMessageDeflateOffer):
            return PerMessageDeflateOfferAccept(offer)


if __name__ == '__main__':
    router_factory = wamp.RouterFactory()
    session_factory = wamp.RouterSessionFactory(router_factory)
    component_config = types.ComponentConfig(realm="realm1")
    component_session = MyBackendComponent(component_config)
    session_factory.add(component_session)

    transport_factory = websocket.WampWebSocketServerFactory(session_factory,
                                                             debug=False,
                                                             debug_wamp=False)
    server = serverFromString(reactor, "tcp:%s" % PORT)
    server.listen(transport_factory)
    reactor.run()
Esempio n. 4
0
    ## 1) create a WAMP router factory
    router_factory = router.RouterFactory()

    ## 2) create a WAMP router session factory
    session_factory = wamp.RouterSessionFactory(router_factory)

    from autobahn.wamp import types

    config = types.ComponentConfig(realm="realm1")

    ## 3) Optionally, add embedded WAMP application sessions to the router
    session_factory.add(MyBackendComponent(config))

    from autobahn.wamp.serializer import MsgPackSerializer, JsonSerializer
    #serializers = [MsgPackSerializer()]
    serializers = [MsgPackSerializer(), JsonSerializer()]

    ## 4) create a WAMP-over-WebSocket transport server factory
    transport_factory = websocket.WampWebSocketServerFactory(session_factory, \
                                                             serializers = serializers, \
                                                             debug = False, \
                                                             debug_wamp = True)

    ## 5) start the server from a Twisted endpoint
    server = serverFromString(reactor, "tcp:8080")
    server.listen(transport_factory)

    ## 6) now enter the Twisted reactor loop
    reactor.run()