根据Qt文档,如果我们想在Windows上使用命名管道,我们可以使用QLocalSocket.我正在用Qt编写服务器和客户端程序.如果我尝试使用WIN32 API在管道中写入一些消息,Qt客户端不会显示它.此外,如果客户端再次使用WIN32 API进行写入,则Qt服务器不会回显发送的消息.QLocalSocket真的推荐用于命名管道吗?
这是Win32 Server代码
wcout << "Creating an instance of a named pipe..." << endl;
// Create a pipe to send data
HANDLE pipe = CreateNamedPipeW(
L"\\\\.\\pipe\\ServicePipe", // name of the pipe
PIPE_ACCESS_OUTBOUND, // 1-way pipe -- send only
PIPE_TYPE_BYTE, // send data as a byte stream
100, // only allow 1 instance of this pipe
0, // no outbound buffer
0, // no inbound buffer
0, // use default wait time
NULL // use default security attributes
); …Run Code Online (Sandbox Code Playgroud)