我创建了我的管道服务器,它使用函数 ConnectNamedPipe 创建了一个管道实例。之后我从管道中读取数据并将数据保存到缓冲区中。我还没有创建我的客户,但我必须做一些操作。
我的客户必须向管道写入 2 件事: 1 - 服务器将执行的操作 - 减法、乘法、加法、除法(我正在尝试实现一种计算器) 2 - 服务器将计算的 2 个数字
我的服务器必须从管道中读取这些操作和 2 个数字并在屏幕上打印结果。
所以,我的问题是,我如何解析客户端编写的这两个操作?
我的服务器工作正常,但解析有问题。
#include <iostream>
#include <Windows.h>
using namespace std;
int main()
{
HANDLE createPipe;
BOOL Connect;
BOOL Read;
int buffer[100];
DWORD numBytesRead;
//Create Pipe
createPipe = CreateNamedPipe(
L"\\\\.\\pipe\\StackOverflow",
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE,
PIPE_UNLIMITED_INSTANCES,
1024,
1024,
NMPWAIT_USE_DEFAULT_WAIT,
NULL);
//Check for failure
if(createPipe == INVALID_HANDLE_VALUE){
cout<<"Failed to create a pipe! "<<endl;
}
//Create instance of the pipe
Connect = ConnectNamedPipe(
createPipe,
NULL);
//Check for failure
if(!(Connect)){
cout<<"Failed to connect to the pipe"<<endl;
CloseHandle(createPipe);
}
//Read bytes from the buffer
Read = ReadFile(
createPipe,
buffer,
99 * sizeof(buffer),
&numBytesRead,
NULL);
//check for failure
if(!(Read)){
cout<<"Failed to read from the pipe"<<endl;
CloseHandle(createPipe);
}
return 0;
}
谢谢