Windows named pipe in node js (preferred shared memory)

I am using named pipe to exchange some data between two processes on windows. One is a node process and the other is a C # process. Here is some sample code I am using in my node process:

var net = require('net');

var PIPE_NAME = "mypipe";
var PIPE_PATH = "\\\\.\\pipe\\" + PIPE_NAME;

var L = console.log;

var server = net.createServer(function(stream) {
    L('Server: on connection')

    stream.on('data', function(c) {
        L('Server: on data:', c.toString());
    });

    stream.on('end', function() {
        L('Server: on end')
        server.close();
    });

    stream.write('Take it easy!');
});

server.on('close',function(){
    L('Server: on close');
})

server.listen(PIPE_PATH,function(){
    L('Server: on listening');
})

      

I am using NamedPipeClientStream in C # to read data. I do this in a loop on both sides, for example my node process is the producer and the C # process is the consumer.

This works great.

But sometimes the C # loop freezes and at this point in my node process I want to overwrite the new data over the old data. I was wondering if I can specify a maximum size in my pipe (the one I create in nodejs) or a timeout for the data, but couldn't find such things in the standard documentation.

If it can't be solved this way, there is a shared memory path to solve the problem, but I haven't been able to find a stable shared memory library for nodejs that works well on windows (and I don't have a lot of time to write one right now). I need some pointers to move in the right direction.

Any advice is appreciated. Thank.

EDIT: I would really like to implement the above stuff using shared memory, as I need to split a large amount of data quickly and I need to tweak it for performance. Any pointers to implementing it?

+3


source to share


1 answer


I figured out a way to use a drain event in a nodejs writeable stream as per my requirement.



+1


source







All Articles