0

I want to pass messages between a Node.js server and a C program that is forked by the Nodejs server. I know there are a lot of possibilities. Here is one on StackOverflow. However, I want the lightest possible mechanism as the server passes one message to the Child process at the start and the Child process sends one at the end. What would be the lightest possible solution for this?

I can think of TCP, UDP, pipes, Unix sockets or just writing to a file and reading from it. TCP sockets would be a heavy solution.

Any suggestion?

Sunny
  • 9,245
  • 10
  • 49
  • 79
  • There is no reason to use TCP if you can use Unix d. sockets. – Antti Haapala -- Слава Україні Nov 13 '17 at 07:21
  • There is no "best" way. You can pick any one of several options that meet your needs. stdin and stdout are probably the most generic, but you could also setup several other methods. – jfriend00 Nov 13 '17 at 09:41
  • Similar question [Interprocess communication between node and c applicatoin](https://stackoverflow.com/questions/16779806/inter-process-communication-between-node-and-c-application) and a module for this [node-ipc](https://www.npmjs.com/package/node-ipc). Google is your friend. Lots of other things to read. – jfriend00 Nov 13 '17 at 09:42

1 Answers1

0

Once you've spawned your child process p you can send it input via STDIN using p.stdin.write().

Marc
  • 13,011
  • 11
  • 78
  • 98