Beispiel #1
0
    def connect(self, url_protocol='ws', url_domain='0.0.0.0', url_port=8080, url_path='ws', debug=False, debug_wamp=False, keep_trying=True, period=5):
        print(datetime.datetime.now(),' - DriverClient.connect:')
        print('\n\targs: ',locals(),'\n')
        if self.transport_factory is None:
            url = url_protocol+"://"+url_domain+':'+str(url_port)+'/'+url_path

            self.transport_factory = websocket.WampWebSocketClientFactory(self.session_factory,
                                                                            url=url,
                                                                            debug=debug,
                                                                            debug_wamp=debug_wamp)

        self.session_factory._handshake = self.handshake
        self.session_factory._dispatch_message = self.dispatch_message

        if not keep_trying:
            try:
                print('\nDriver attempting crossbar connection\n')
                self._make_connection(url_domain=url_domain, url_port=url_port)
            except:
                print('crossbar connection attempt error:\n',sys.exc_info())
                pass
        else:
            while True:
                while (self.session_factory._crossbar_connected == False):
                    try:
                        print('\nDriver attempting crossbar connection\n')
                        self._make_connection(url_domain=url_domain, url_port=url_port)
                    except KeyboardInterrupt:
                        self.session_factory._crossbar_connected = True
                    except:
                        print('crossbar connection attempt error:\n',sys.exc_info())
                        pass
                    finally:
                        print('\nDriver connection failed, sleeping for 5 seconds\n')
                        time.sleep(period)
Beispiel #2
0
def magic_box(sproto, extra):
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)
    component_config = types.ComponentConfig(realm="realm1", extra=extra)
    session_factory = wamp.ApplicationSessionFactory(config=component_config)
    session_factory.session = sproto
    transport_factory = websocket.WampWebSocketClientFactory(session_factory)
    coro = loop.create_connection(transport_factory, '127.0.0.1', 9002)
    loop.run_until_complete(coro)
    loop.run_forever()
    loop.close()
    return
Beispiel #3
0
def run_client(application_class):
    """Run autobahn application"""

    session_factory = wamp.ApplicationSessionFactory()
    session_factory.session = application_class
    transport_factory = websocket.WampWebSocketClientFactory(session_factory,
                                                             debug=False,
                                                             debug_wamp=False)

    loop = asyncio.get_event_loop()
    return loop.run_until_complete(
        loop.create_connection(transport_factory, '0.0.0.0', 8080))
Beispiel #4
0
loop = asyncio.get_event_loop()
try:
    session_factory = wamp.ApplicationSessionFactory()
    session_factory.session = WampComponent

    session_factory._myAppSession = None

    # TODO: should not be hardcoded but rather moved to setting file...
    url = "ws://127.0.0.1:31947/ws"

    serializers = []

    serializers.append(JsonSerializer())
    serializers.append(MsgPackSerializer())

    transport_factory = websocket.WampWebSocketClientFactory(
        session_factory, url=url, serializers=serializers)

    subscriber = Subscriber(session_factory, loop)
    publisher = Publisher(session_factory)

    while (crossbar_status == False):
        try:
            logger.info('trying to make a connection...')
            make_a_connection()
            disconnect_counter = 0
        except KeyboardInterrupt:
            crossbar_status = True
            logger.info(
                "WAMP router connection cancelled due to user keyboard interrupt"
            )
        except Exception as e:
Beispiel #5
0
        self.disconnect()

    def onDisconnect(self):
        print("on-disconnect")
        asyncio.get_event_loop().stop()


if __name__ == '__main__':

    ## 1) create a WAMP application session factory
    session_factory = wamp.ApplicationSessionFactory()
    session_factory.session = MyFrontendComponent

    ## 2) create a WAMP-over-WebSocket transport client factory
    transport_factory = websocket.WampWebSocketClientFactory(session_factory,
                                                             debug=False,
                                                             debug_wamp=False)

    ## 3) start the client
    loop = asyncio.get_event_loop()
    coro = loop.create_connection(transport_factory, ws_const.CONNECT_ADDRESS,
                                  ws_const.PORT)
    loop.run_until_complete(coro)
    ## 4) now enter the asyncio event loop
    try:
        loop.run_forever()
    except KeyboardInterrupt:
        pass
    finally:
        loop.close()