Named pipe client (ACE, ACE_SPIPE_Connector) could not connect to csharp (NamedPipeServerStream) server

120 views Asked by At

I have a problem connecting a C++ client with an ACE_SPIPE_Connector (ACE) to a .NET server. While a test with an echo to the address \.\pipe\pipename works, I suspect an issue with my C++ code using the ACE libraries.

Here is the .NET server code:

var server = new NamedPipeServerStream("acepipe");

server.WaitForConnection();
StreamReader reader = new StreamReader(server);

var line = reader.ReadLine();
Console.WriteLine(line);

And here is the C++ client code:

#if defined (ACE_WIN32)
#define MAKE_PIPE_NAME(X) ACE_TEXT ("\\\\.\\pipe\\") ACE_TEXT (X)
#else
#define MAKE_PIPE_NAME(X) ACE_TEXT (X)
#endif

const ACE_TCHAR *rendezvous = MAKE_PIPE_NAME("acepipe");

ACE_SPIPE_Stream cli_stream;
ACE_SPIPE_Connector con;
int i;

if (con.connect(cli_stream,
    ACE_SPIPE_Addr(rendezvous)) == -1)
{
    printf("Named pipe connect failed.\n%s\n", rendezvous);
    return 0;
}

I have no idea what is wrong here.

Any help?

Thanks, Lothar

1

There are 1 answers

0
lollisoft On

Meanwhile I have found the issues with the code. Two points or problems:

1.) The named pipe name it self was different .\pipe\acepipe (C++) vs .\acepipe (C#).

2.) The mode (message vs byte). ACE Defaulted to message and C# didn't.

The following C# code solved the issue:

var server = new NamedPipeServerStream("acepipe", PipeDirection.InOut, 4, PipeTransmissionMode.Message);

server.WaitForConnection();