0

.net NamedPipeClientStreamクラスを使用して NamedPipes サーバーから読み取る場合、C++ での最初の読み取りでのみデータを取得できます。毎回、空の文字列になります。c# では毎回動作します。

pipeClient = gcnew NamedPipeClientStream(".", "Server_OUT", PipeDirection::In);

try
{
    pipeClient->Connect();
}
catch(TimeoutException^ e)
{
    // swallow
}

StreamReader^ sr = gcnew StreamReader(pipeClient);
String^ temp;
while (temp = sr->ReadLine())
{
    // = sr->ReadLine();
    Console::WriteLine("Received from server: {0}", temp);
}
sr->Close();
4

1 に答える 1

0

この問題は、C++ ヌル ターミネータに関連していました。たとえば、NamedPipes サーバーが送信していた

"ハローワールド!\n\0"

最初のパスでこれが送信されます

"Hello World!\n"パイプに\0を残します。後続の送信では、送信します

"\0ハローワールド!\n"

C# は文字列全体を取得しますが、C++ は\0文字で文字列を終了します。

于 2009-11-05T12:09:46.963 に答える