我的代码在服务器端调用了两个函数sendMatrixPos和sendMatrixTrack来顺序发送两个矩阵。我将矩阵 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();
}
另一方面,我在客户端有两个调用函数,以便每帧从服务器顺序接收两个矩阵。
客户
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 协议。我需要同时发送和接收两个矩阵(不是按顺序),这一步该怎么做?或如何同时发送两个矩阵?
客户端的BUFFERSIZE 1024和服务器端的1024 ...