Esempio n. 1
0
def main():
    parser = argparse.ArgumentParser(description=None)
    parser.add_argument('-v',
                        '--verbose',
                        action='count',
                        dest='verbosity',
                        default=0,
                        help='Set verbosity.')
    parser.add_argument('-l',
                        '--listen-address',
                        default='127.0.0.1:15896',
                        help='Address to listen on')
    parser.add_argument('-o',
                        '--botaction-logfile',
                        default='/tmp/demo/botactions.jsonl',
                        help='Filename for timestamped log of bot actions.')
    args = parser.parse_args()

    BotactionRecordingServer.logfile_path = args.botaction_logfile

    if args.verbosity == 0:
        logger.setLevel(logging.INFO)
    elif args.verbosity >= 1:
        logger.setLevel(logging.DEBUG)

    factory = websocket.WebSocketServerFactory()
    factory.protocol = BotactionRecordingServer

    host, port = args.listen_address.split(':')
    port = int(port)
    logger.info('Listening on %s:%s', host, port)
    reactor.listenTCP(port, factory)
    reactor.run()
    return 0
Esempio n. 2
0
    def listen(self, port=15900):
        logger.info('Starting Rewarder on port=%s', port)
        factory = websocket.WebSocketServerFactory()
        factory.agent_conn = self
        factory.protocol = RewarderProtocol

        reactor.callFromThread(reactor.listenTCP, port, factory)
Esempio n. 3
0
    def __init__(self, wsgiapp, wsprotocol, port=PORT):
        ''' Start protocol factory and reactor
        '''
        self.app = wx.GetApp()
        ip = self.app.IP
        self.ip = "127.0.0.1" if ip is None else ip
        self.port = port
        self.url = "ws://%s:%s" % (self.ip, self.port)

        # Set Protocol factory
        self.factory = websocket.WebSocketServerFactory(self.url)
        self.factory.protocol = wsprotocol

        self.root = WSGIRoot()
        self.root.WSGI = WSGIResource(reactor, reactor.getThreadPool(),
                                      wsgiapp)
        self.root.putChild(b"ws", resource.WebSocketResource(self.factory))

        static = File(os.path.join(self.app.path['www'], 'static'))
        self.root.putChild(b"static", static)
        # Only one File
        #self.root.putChild(b"documentation", File( os.path.join(self.app.path['www'], 'documentation') ) )

        self.site = Site(self.root)

        # Use the existing reactor
        reactor.listenTCP(self.port, self.site)

        echo("Web Server: Starting at %s" % self.root)
        echo("Websockets Server: Starting at %s" % self.url)

        topic = "ws.local"
        self.topic = topic
        self.factory.protocol.topic = topic
        self.Initialize()
Esempio n. 4
0
def main():
    parser = argparse.ArgumentParser(description=None)
    parser.add_argument('-v', '--verbose', action='count', dest='verbosity', default=0, help='Set verbosity.')
    parser.add_argument('-l', '--listen-address', default='0.0.0.0:15899', help='Address to listen on')
    parser.add_argument('-s', '--rewarder-address', default='127.0.0.1:15900', help='Address of the reward server to run on.')
    parser.add_argument('-o', '--reward-logfile', default='/tmp/demo/rewards.demo', help='Timestamped log of client data.')
    parser.add_argument('-d', '--logfile-dir', default='/tmp/demo', help='Base directory to write logs for each connection')
    args = parser.parse_args()

    if args.verbosity == 0:
        logger.setLevel(logging.INFO)
    elif args.verbosity >= 1:
        logger.setLevel(logging.DEBUG)

    factory = websocket.WebSocketServerFactory()
    factory.protocol = reward_proxy_server.RewardProxyServer
    factory.logfile_dir = args.logfile_dir
    factory.setProtocolOptions(maxConnections=1)  # We only write reward logs to one place, so only allow one connection

    host, port = args.listen_address.split(':')
    port = int(port)
    logger.info('Listening on %s:%s', host, port)
    reactor.listenTCP(port, factory)
    reactor.run()
    return 0
Esempio n. 5
0
    def __init__(self,
                 app,
                 protocol=None,
                 ip=None,
                 port=PORT,
                 path=b"ws",
                 www=None):
        ''' Start protocol factory and reactor
        '''
        #self.io_control()

        self.app = app
        self.ip = "127.0.0.1" if ip is None else ip
        self.port = port
        self.url = "ws://%s:%s" % (self.ip, self.port)

        if protocol is None:
            protocol = WebSocketProtocol

        self.root = File(app.path['www'] if www is None else www)

        self.factory = websocket.WebSocketServerFactory(self.url)
        self.factory.protocol = protocol

        self.root.putChild(path, resource.WebSocketResource(self.factory))
        self.site = Site(self.root)

        # Use the existing reactor
        reactor.listenTCP(self.port, self.site)

        self.Initialize()