简体   繁体   English

OS服务与C ++之间的通信

[英]communication between OS services with c++

I am developing 2 Windows services, one of them will send pictures and word files to other and other service will give a string answer. 我正在开发2个Windows服务,其中一个会将图片和Word文件发送给其他,而其他服务将给出字符串答案。 That services are in same computer. 这些服务在同一台计算机中。

I will develop same program's Linux version also. 我还将开发相同程序的Linux版本。

Which way is the best for communication between services in Linux and Windows. 哪种方式最适合Linux和Windows中的服务之间的通信。

By the way I am developing that services with C++. 顺便说一下,我正在用C ++开发该服务。

I would suggest reading up on C++ sockets. 我建议阅读C ++套接字。 You're probably going to want to use TCP sockets, since you want to ensure that the data being transferred does so correctly. 您可能要使用TCP套接字,因为您要确保正在传输的数据正确执行。

Try checking these links out: 尝试检查以下链接:

Linux Sockets Linux套接字

Windows Sockets Windows套接字

You should search for IPC . 您应该搜索IPC
There are a lot of possibilities for inter process communication. 进程间通信有很多可能性。 Because you are not very specific about your problem and your requirements but I would suggest to take a look at boost::interprocess . 因为您对问题和要求不是很明确,但是我建议您看一下boost :: interprocess

As long as you are sure that both services run on the same machine this will do it. 只要您确定两个服务都在同一台计算机上运行,​​就可以做到。
If you want to switch to a distributed approach you need something different. 如果您想切换到分布式方法,则需要一些不同的东西。
Like XML-RPC , thrift or corba . XML-RPCthriftcorba一样 Just to mention some possibilities. 仅提及一些可能性。

There're different options for your task: 您的任务有不同的选择:

  1. Network. 网络。 Establish TCP connection between your services, with service that asks as a client and service that answers as a server. 在服务之间建立TCP连接,将服务作为客户端请求,将服务作为服务器响应。 It's possible to implement cross-platform solution using Boost.Asio or any other portable network library. 可以使用Boost.Asio或任何其他便携式网络库来实现跨平台解决方案。
  2. Shared memory. 共享内存。 You can implement inter-process communication using shared memory. 您可以使用共享内存来实现进程间通信。 Cross-platform library: Boost.Interprocess. 跨平台库:Boost.Interprocess。
  3. Pipes. 管道。 I don't know cross-platform library for this. 我不知道跨平台的库。

I would recommend to use TCP communication as more flexible solution. 我建议使用TCP通信作为更灵活的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM