17

Say I've got a c++ program running on the same server with a Node.js web app, on a linux server.

The c++ program maintains a queue, and what I want to do with Node.js is, push some data into the queue.

What's the best way to do this?

Which is better? sockets or IPC?

1
  • We used dbus to communicate between C++ and nodejs on our embedded system. DBUS is a default bus on linux systems.
    – Frank Roth
    Commented May 9, 2017 at 11:31

3 Answers 3

13

If you're using Linux, I would suggest UNIX-domain sockets. They basically give you the high-performance of IPC using the BSD socket interface, making it easy to switch for TCP sockets later if you need to move the C++ (or node.js) application to a different computer.

They're already supported by node.js and only the code that opens the socket will need to be changed. Many applications, including MySQL easily abstract this away in a configuration file.

2

I'd use sockets, they are clean and easy to use

8
  • but actually they're on the same server, I'm wondering socket may be slow than IPC things, am I right?
    – NamiW
    Commented Mar 23, 2012 at 16:59
  • it is definitely slower but it will prepare your app to scale if someday the two wont reside anymore on the same server.
    – luke14free
    Commented Mar 23, 2012 at 17:17
  • @luke14free: that depends. Unix sockets might be faster than regular TCP sockets. Commented Mar 23, 2012 at 17:51
  • @AndréCaron ICP = Interprocess Communications Protocol not TCP ;)
    – luke14free
    Commented Mar 23, 2012 at 18:04
  • 2
    @luke14free: Google has not heard of an ICP "interprocess communications protocol". I think you meant IPC = Inter-Process Communication. Since OP specified Linux is the OS, the best platform-specific IPC likely to be supported by node.js is Unix-domain sockets, which are likely to give better performance than TCP sockets. Commented Mar 23, 2012 at 18:56
2

If you want to use an IPC mechanism, you may consider writing a Node.js C++ module, and then use something from the Boost.Interprocess library to communicate with your other app.

Boost.Interprocess has mechanisms already build for sharing containers from the standard library. Its also cross platform if you want to be open to that in the future.

Not the answer you're looking for? Browse other questions tagged or ask your own question.