名前付きパイプ通信を介して c# と C++ (QT) アプリケーション間でデータを渡す際に問題に直面しています。C# クライアント アプリケーションは、C++ の NamedPipe サーバーに接続しますが、サーバー上でメッセージが正しく解析されません。例として、短い変数の値 = 2 と C++ コード解析バイト配列を unsigned int に送信していますが、値はサーバーで常にゼロになります。私が間違っていることを教えてください。
クライアントとサーバーのコード:
QT ライブラリを使用した C++ の NamedPipe サーバー コード
QLocalSocket *local_socket = _local_server->nextPendingConnection();
if (!local_socket->waitForReadyRead(gft::PROC_TIMEOUT)) {
qDebug() << "gft_plugin: timeout while waiting for data";
return;
}
int bytesavailable = local_socket->bytesAvailable();
QByteArray buffer;
QDataStream in(&buffer, QIODevice::ReadOnly);
buffer.append(local_socket->readAll());
unsigned int msg;
in >> msg;
unsigned int a_id = msg;
NamedPipe クライアント (C#)
var clientStream = new NamedPipeClientStream("localhost", "gft_plugin_server", PipeDirection.InOut);
clientStream.Connect();
if (clientStream.IsConnected)
{
_stop = false;
UInt16 a_id = 2;
byte[] b = BitConverter.GetBytes(a_id);
clientStream.Write(b, 0, b.Count());
clientStream.Flush();
}
else
{
MessageBox.Show("Could not connected");
}