node/dlpa/lib/dlpa.js
function Server(config) {
        RED.nodes.createNode(this, config);

        // Start a DLPA server.
        // Options:
        //   --port PORT           Listening port number.
        //   --clients CLIENTS     The number of clicents.
        //   --max-workers MAX_WORKERS
        //                         The maximum number of workiers (default: 10).
        const proc = spawn("python3", [
            "-m", "dlpa.server",
            "--port", config.port,
            "--clients", config.nclient,
            "--key-length", "128",
            "--time-span", config.span ? config.span : "300"
        ], {
            cwd: __dirname,
        });
        let exited = false;
        proc.on("exit", (code, signal) => {
            this.log(`DLPA server is closed: ${signal}`);
            exited = true;
        })
        const logger = readline.createInterface({
            input: proc.stderr
        });
        logger.on("line", (line) => {
            this.log(line);
        })

        // Wait results which should be outputted into stderr; and then
        // post a message based on each output.
        const rl = readline.createInterface({
            input: proc.stdout
        });
        rl.on("line", (line) => {
            const payload = JSON.parse(line);
            this.send({
                "topic": config.topic,
                "payload": matrix(
                    parseInt(config.rows, 10),
                    parseInt(config.columns, 10),
                    payload.value.map(v => (v / MAG) - MAG))
            });
        });

        // Stop the server.
        this.on("close", (done) => {
            if (exited) {
                done();
                return;
            }

            // Wait the server is closed.
            proc.on("exit", () => {
                done();
            });

            // Send a signal.
            this.log("DLPA server is closing");
            proc.stdin.close();
            rl.close();
            logger.close();
            proc.kill();

        });

    }
function Server(config) {
        RED.nodes.createNode(this, config);

        // Start a DLPA server.
        // Options:
        //   --port PORT           Listening port number.
        //   --clients CLIENTS     The number of clicents.
        //   --max-workers MAX_WORKERS
        //                         The maximum number of workiers (default: 10).
        const proc = spawn("python3", [
            "-m", "dlpa.server",
            "--port", config.port,
            "--clients", config.nclient,
            "--key-length", "128",
            "--time-span", config.span ? config.span : "300"
        ], {
            cwd: __dirname,
        });
        let exited = false;
        proc.on("exit", (code, signal) => {
            this.log(`DLPA server is closed: ${signal}`);
            exited = true;
        })
        const logger = readline.createInterface({
            input: proc.stderr
        });
        logger.on("line", (line) => {
            this.log(line);
        })

        // Wait results which should be outputted into stderr; and then
        // post a message based on each output.
        const rl = readline.createInterface({
            input: proc.stdout
        });
        rl.on("line", (line) => {
            const payload = JSON.parse(line);
            this.send({
                "topic": config.topic,
                "payload": matrix(
                    parseInt(config.rows, 10),
                    parseInt(config.columns, 10),
                    payload.value.map(v => (v / MAG) - MAG))
            });
        });

        // Stop the server.
        this.on("close", (done) => {
            if (exited) {
                done();
                return;
            }

            // Wait the server is closed.
            proc.on("exit", () => {
                done();
            });

            // Send a signal.
            this.log("DLPA server is closing");
            proc.stdin.close();
            rl.close();
            logger.close();
            proc.kill();

        });

    }
function Server ( config ) { RED . nodes . createNode ( this , config ) ; // Start a DLPA server. // Options: //   --port PORT           Listening port number. //   --clients CLIENTS     The number of clicents. //   --max-workers MAX_WORKERS //                         The maximum number of workiers (default: 10). const proc = spawn ( "python3" , [ "-m" , "dlpa.server" , "--port" , config . port , "--clients" , config . nclient , "--key-length" , "128" , "--time-span" , config . span ? config . span : "300" ] , { cwd : __dirname , } ) ; let exited = false ; proc . on ( "exit" , ( code , signal ) => { this . log ( ` ${ signal } ` ) ; exited = true ; } ) const logger = readline . createInterface ( { input : proc . stderr } ) ; logger . on ( "line" , ( line ) => { this . log ( line ) ; } ) // Wait results which should be outputted into stderr; and then // post a message based on each output. const rl = readline . createInterface ( { input : proc . stdout } ) ; rl . on ( "line" , ( line ) => { const payload = JSON . parse ( line ) ; this . send ( { "topic" : config . topic , "payload" : matrix ( parseInt ( config . rows , 10 ) , parseInt ( config . columns , 10 ) , payload . value . map ( v => ( v / MAG ) - MAG ) ) } ) ; } ) ; // Stop the server. this . on ( "close" , ( done ) => { if ( exited ) { done ( ) ; return ; } // Wait the server is closed. proc . on ( "exit" , ( ) => { done ( ) ; } ) ; // Send a signal. this . log ( "DLPA server is closing" ) ; proc . stdin . close ( ) ; rl . close ( ) ; logger . close ( ) ; proc . kill ( ) ; } ) ; }
DLPA Server Node.
DLPA Server Node .