I want to communicate between NodeJS and a C program using node-ipc, over a Unix socket, which according to that homepage is the fastest option. (They will be on the same machine). That package claims it could communicate with a C program. (I had to sanity check).
The problem is the examples don't give example C code, and I have next to no idea how I'd get them to talk.
Can anyone point me to an example of C code to match those client/server examples? For example, how would I adapt this tutorial on working with unix pipes in C (Assuming I'm not completely off track?! Maybe it's "domain sockets" that I want instead?) None of this is making any sense to me, I'm missing something crucial.
I think that you should be looking for C unix domain sockets, not pipes. Pipes are different. Look for some C code examples on Google with unix domain sockets, try a few out, get that working, then go back to the node-ipc stuff.
I took the node-ipc and node.js tags off because Node isn't relevant if you are trying to figure out the C side first.
I got it to work in the end with the code below. You can have it for free!
server.c
client.js:
On a side note, I've realised that if you just want to do communicate between NodeJS via unix sockets with C, NodeJS actually comes with a module that does that already. Which as it turns out, is what
node-ipc
uses under the hood. So it might be easier just to use NodeJS'snet
package instead. This previous question points out how to do IPC in NodeJS. Just combine that with the above C code.