问题描述
我写了两对命名管道客户端/服务器程序:
第一对C#(.NET 4)
第二对C ++(非管理)
I wrote 2 pairs of named pipe client/server programs:1st pair in C# (.NET 4)2nd pair in C++ (un-managed)
所有4个测试程序使用相同的管道名称\\.\pipe\mypipe
All 4 test programs use the same pipe name \\.\pipe\mypipe
C#对彼此工作正常 - 我从客户端发送一条消息,它被服务器接收。
The C# pair work fine with each other - I send a message from the client and it is received by the server.The C++ pair work also fine with each other.
但是...当我尝试使用C ++服务器或C ++客户端运行C#客户端时与C#服务器 - 然后它不工作。客户端无法连接到服务器。
But... when I try to run the C# client with the C++ server, or the C++ client with the C# server - then it doesn't work. The client is unable to connect to the server.
有没有阻止C ++客户端使用.NET服务器的东西?
它应该工作吗?
Is there something preventing the C++ client from working with the .NET server?Should it work?
谢谢。
推荐答案
NamedPipeClientStream
和 NamedPipeServerStream
自动将前缀\\.\\\\\\\\\\\\\\
NamedPipeClientStream
and NamedPipeServerStream
prefix "\\.\pipe\" to the name automatically.
C ++客户端代码:
C++ client code:
hPipe = CreateFile("\\\\.\\pipe\\mypipe", ...)
相应的C#服务器代码:
corresponding C# server code:
var pipe = new NamedPipeServerStream("mypipe", ...)
这篇关于命名管道:C#服务器,C ++客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!