稍微研究了一下windows各种进程通信,要求复杂度小、高效率的、双向的、不跨计算机的(不涉及网络的),只专注本地进程通信,总结出2种方式:
第一种:windows named pipe
windows pipe可以实现双向通信,一个pipe就能实现,如果涉及阻塞、同步异步、锁…这带来了复杂度提升,因此觉得一个pipe只要专注单向传输就好了,如果要涉及双向传输,使用2个pipe。以下是一种单向传输的实现,适用于高速同步模型:
server.cpp,用来接收消息:
#include<Windows.h>
#include<iostream>
#include<chrono>
#include<future>
using std::cout;
using std::endl;
int main(void)
{
HANDLE hPipe;