Exemplo n.º 1
0
def ws_api():
    class ChooWebsocketServerProtocol(WebSocketServerProtocol):
        def onConnect(self, request):
            pass

        def onOpen(self):
            self.instance = ChooInstance(lambda r: self.sendMessage(r))

        def onMessage(self, payload, isBinary):
            result = self.instance.handle_msg(payload)
            self.sendMessage(result)

        def connectionLost(self, reason):
            self.instance.abort_queries()

    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)

    factory = WebSocketServerFactory('ws://%s:%d' %
                                     (args.ws_host, args.ws_port))

    factory.protocol = ChooWebsocketServerProtocol
    factory.setProtocolOptions(allowHixie76=True)

    loop = asyncio.get_event_loop()
    coro = loop.create_server(factory, args.ws_host, args.ws_port)
    loop.run_until_complete(coro)
    loop.run_forever()
Exemplo n.º 2
0
def startServer():
    factory = WebSocketServerFactory()
    factory.protocol = ServerProtocol
    factory.setProtocolOptions(autoPingInterval=1)
    factory.setProtocolOptions(requireMaskedClientFrames=False)
    loop = asyncio.get_event_loop()
    coro = loop.create_server(factory, HOST, PORT)
    server = loop.run_until_complete(coro)
    print('Autobahn server is started at ws://{}:{}'.format(HOST, PORT))

    try:
        loop.run_forever()
    except KeyboardInterrupt:
        pass
    finally:
        server.close()
        loop.close()
Exemplo n.º 3
0
    def talker(self):
        # In ROS, nodes are uniquely named. If two nodes with the same
        # node are launched, the previous one is kicked off. The
        # anonymous=True flag means that rospy will choose a unique
        # name for our 'talker' node so that multiple talkers can
        # run simultaneously.
        port_env_var = "BLOCKLY_PORT"
        if port_env_var in os.environ:
            blockly_port = int(os.environ[port_env_var])
        else:
            blockly_port = 9000
        ws_factory_string = str("ws://0.0.0.0:" + str(blockly_port))

        rospy.init_node('blockly_server', anonymous=True)
        rospy.Subscriber("blockly", String, RobotBlocklyBackend.callback)
        CodeStatus.initialize_publisher()
        self.__current_block_publisher = rospy.Publisher('current_block_id',
                                                         String,
                                                         queue_size=5)

        rospy.Service('program_is_paused', Trigger,
                      RobotBlocklyBackend.__is_status_paused)
        rospy.Service('program_completed', Empty,
                      RobotBlocklyBackend.__set_status_completed)
        rospy.Service('program_set_current_block_id', SetCurrentBlockId,
                      self.__set_current_block_id)

        factory = WebSocketServerFactory(u"ws://0.0.0.0:9000")
        factory.protocol = BlocklyServerProtocol
        factory.setProtocolOptions(autoPingInterval=1,
                                   autoPingTimeout=3,
                                   autoPingSize=20)

        loop = asyncio.get_event_loop()
        coro = loop.create_server(factory, '0.0.0.0', 9000)
        server = loop.run_until_complete(coro)
        asyncio. async (RobotBlocklyBackend.wait_until_ros_node_shutdown(loop))

        loop.run_forever()

        print("Closing...")
        server.close()
        loop.run_until_complete(server.wait_closed())
        loop.close()
Exemplo n.º 4
0
        loult_state.can_ban = True
    except BanFail:
        loult_state.can_ban = False
        logger.warning("nft command dosen't work; bans are disabled.")


    class AutobahnLoultServer(LoultServer, WebSocketServerProtocol):
        loult_state = loult_state
        client_logger = logging.getLogger('client')


    factory = WebSocketServerFactory(server='Lou.lt/NG') # 'ws://127.0.0.1:9000',
    factory.protocol = AutobahnLoultServer
    # Allow 4KiB max size for messages, in a single frame.
    factory.setProtocolOptions(
            autoPingInterval=60,
            autoPingTimeout=30,
        )

    coro = loop.create_server(factory, '127.0.0.1', 9000)
    scheduler_task = ensure_future(scheduler.start())
    server = loop.run_until_complete(gather(coro, scheduler_task))

    try:
        loop.run_forever()
    except KeyboardInterrupt:
        logger.info('Shutting down all connections...')
        for client in chain.from_iterable((channel.clients for channel in loult_state.chans.values())):
            client.sendClose(code=1000, reason='Server shutting down.')
        loop.close()
        print('aplse')
Exemplo n.º 5
0
        loop.run_until_complete(Ban.test_ban())
        loult_state.can_ban = True
    except BanFail:
        loult_state.can_ban = False
        logger.warning("nft command dosen't work; bans are disabled.")

    class AutobahnLoultServer(LoultServer, WebSocketServerProtocol):
        loult_state = loult_state
        client_logger = logging.getLogger('client')

    factory = WebSocketServerFactory(
        server='Lou.lt/NG')  # 'ws://127.0.0.1:9000',
    factory.protocol = AutobahnLoultServer
    # Allow 4KiB max size for messages, in a single frame.
    factory.setProtocolOptions(
        autoPingInterval=60,
        autoPingTimeout=30,
    )

    coro = loop.create_server(factory, '127.0.0.1', 9000)
    scheduler_task = ensure_future(scheduler.start())
    server = loop.run_until_complete(gather(coro, scheduler_task))

    try:
        loop.run_forever()
    except KeyboardInterrupt:
        logger.info('Shutting down all connections...')
        for client in chain.from_iterable(
            (channel.clients for channel in loult_state.chans.values())):
            client.sendClose(code=1000, reason='Server shutting down.')
        loop.close()
        print('aplse')
Exemplo n.º 6
0
        loult_state.can_ban = True
    except BanFail:
        loult_state.can_ban = False
        logger.warning("ipset command dosen't work; bans are disabled.")

    class AutobahnLoultServer(LoultServer, WebSocketServerProtocol):
        loult_state = loult_state
        client_logger = logging.getLogger('client')

    factory = WebSocketServerFactory(
        server='Lou.lt/NG')  # 'ws://127.0.0.1:9000',
    factory.protocol = AutobahnLoultServer
    # Allow 4KiB max size for messages, in a single frame.
    factory.setProtocolOptions(
        autoPingInterval=60,
        autoPingTimeout=30,
        maxFramePayloadSize=4096,
        maxMessagePayloadSize=4096,
    )

    coro = loop.create_server(factory, '127.0.0.1', 9000)
    server = loop.run_until_complete(coro)

    try:
        loop.run_forever()
    except KeyboardInterrupt:
        logger.info('Shutting down all connections...')
        for client in chain.from_iterable(
            (channel.clients for channel in loult_state.chans.values())):
            client.sendClose(code=1000, reason='Server shutting down.')
        loop.close()
        print('aplse')