私のコードでは、サーバー側でsendMatrixPosとsendMatrixTrackの 2 つの関数を呼び出して、 2 つの行列を順番に送信しています。そして、私は行列evrey framをクライアントに送りました
サーバ
void MyTestPlugin::sendMSGP()
{
if(!connected)
return;
if ( (numbytes = send(client_skt, buf, 16*sizeof(float) ,0)) == -1){
std::cerr<<"server, normal send error"<<std::endl;
exit(1);
}
}
void MyTestPlugin::sendMSGT()
{
if(!connected)
return;
if ( (numbytes = send(client_skt, trackBuf, 16*sizeof(float) ,0)) == -1){
std::cerr<<"server, normal send error"<<std::endl;
exit(1);
}
}
void MyTestPlugin::sendMatrixPos()
{
if(!connected)
return;
Matrixd transNode = PluginHelper::getObjectMatrix();
for (int i=0; i<4; ++i)
for (int j=0; j<4; ++j)
matrixP[i*4+j] = transNode(i,j);
for(int i=0; i<16; i++)
{
cerr <<"matrixP:" << i << " " << matrixP[i] << endl;
}
memcpy(buf,matrixP,sizeof(float)*16);
sendMSGP();
}
void MyTestPlugin::sendMatrixTrack()
{
if(!connected)
return;
Matrixd trackNode = PluginHelper::getHeadMat(1);
for (int i=0; i<4; ++i)
for (int j=0; j<4; ++j)
matrixT[i*4+j] = trackNode(i,j);
for(int i=0; i<16; i++)
{
cerr <<"matrixT:" << i << " " << matrixT[i] << endl;
}
memcpy(trackBuf,matrixT,sizeof(float)*16);
sendMSGT();
}
void MyTestPlugin::preFrame()
{
sendMatrixPos();
sendMatrixTrack();
}
一方、フレームごとにサーバーから 2 つの行列を順番に受信する関数のクライアントで 2 つの呼び出しがあります。
クライアント
void osgMain::draw()
{
recvMSG();
...
recvMSG();
}
void osgMain::recvMSG()
{
numbytes = recv(client_skt, buf, bufferSize,0);
if ( numbytes == -1 ){
//__android_log_print(ANDROID_LOG_ERROR,"jni client","recv error");
//exit(1);
}
else
{
memcpy (matrix, buf, numbytes);
}
}
TCP/IP プロトコルを使用しました。2 つのマトリックスを送信し、同時に (順次ではなく) 受信する必要があります。この手順を実行するにはどうすればよいですか? または 同時に 2 つの行列を送信するにはどうすればよいですか?
クライアント側のBUFFERSIZE 1024とサーバー側の1024 ...