Create a FIFO pipe in C for reading
// Copyright Robert Eisele 2017
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main() {
char *fifo = "/tmp/fifoPipe";
mkfifo(fifo, 0666);
int fd = open(fifo, O_RDONLY);
while (1) {
double d;
int x = read(fd, &d, sizeof(double));
printf("%f\n", d);
}
close(fd);
return 0;
}
Now connect to the pipe using node.js and write data to it:
// Copyright Robert Eisele 2017
var fs = require("fs");
fs.open("/tmp/fifoPipe", "w", function(fd){
console.log("open", fd);
while(1) {
fs.write(fd, Buffer.from([1,2,3,4]), function() {
console.log("done");
});
}
});