Nodejs与C ++程序通信? [英] Nodejs communicate with C++ program?
问题描述
假设我在Linux服务器上运行了一个带有Node.js Web应用程序的同一服务器上的c ++程序。
Say I've got a c++ program running on the same server with a Node.js web app, on a linux server.
c ++程序维护一个队列我想用Node.js做的是将一些数据推入队列。
The c++ program maintains a queue, and what I want to do with Node.js is, push some data into the queue.
最好的方法是什么?
哪个更好?套接字或IPC?
Which is better? sockets or IPC?
推荐答案
如果您使用的是Linux,我建议 UNIX域套接字。它们基本上使用BSD套接字接口为您提供高性能的IPC,如果您需要将C ++(或node.js)应用程序移动到另一台计算机,可以在以后轻松切换TCP套接字。
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.
他们 node.js已经支持,只需要打开套接字的代码要改变。许多应用程序(包括MySQL)都可以在配置文件中轻松抽象出来。
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.
这篇关于Nodejs与C ++程序通信?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!