-3
我创建了我的管道服务器,它使用函数ConnectNamedPipe创建管道实例 管道。之后,我从管道读取数据并保存到缓冲区。 我还没有创建我的客户端,但我必须做一些操作。如何解析通过管道接收的消息
我的客户写信给管两件事: 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;
}
THX
这是功课? – sashoalm 2012-04-18 16:58:29
我希望..我想这样做因为它可以帮助我提高我的编程技巧 – user1341970 2012-04-18 16:59:46
好的。你的头衔说问题是通过管道传递数据。所以你用客户端发送数据,但没有到达服务器,对吗? – sashoalm 2012-04-18 17:03:50