如何使用TCP / IP在c ++中同时将许多矩阵从服务器发送到客户端,反之亦然
How can I send many matrices from server to client at the same time and vice versa in c++ using TCP/IP?
我的代码中有两个服务器端的两个函数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...
您的传输将受到"网络管道大小"的限制 - 除非您有 40Gb/s 的网卡,否则您不太可能从尝试并行发送数据中受益 - 您只会使您的代码更加复杂 - 只要您的代码被编写为异步发送/接收,这就是您所需要的。
相关文章:
- "unknown ca"自生成的 CA、证书和客户端/服务器
- 当我编译webrtc服务器时,Windows上只支持clang-cl
- 在混合代码库中将C转换为C++时出现许多包含错误
- 如何通过套接字将文本文件的内容从服务器发送到客户端
- 有没有办法知道Tracer是否成功地完全连接到了jaegerclientcpp中的jaeger后端服务器
- 从服务器传输到客户端的消息不会出现
- QTcpSocket在不阻塞GUI的情况下重新连接到服务器
- OpenSSL TLS服务器-使用客户端证书白名单
- 我正在开发服务器,ip作为参数传递不起作用
- 我可以与 python 服务器而不是 c++ 客户端建立 tcp/ip 套接字吗?
- 函数在许多数字上转换为基数 1 时减去 2?
- 提升 Asio TCP 服务器 处理多个客户端
- C++函数中的精确"return"矩
- 如何在 Minecraft 服务器上执行命令
- 调试编译的服务器在数据库打开时崩溃
- CPU 瓶颈;处理具有许多非静态对象的 3D 场景渲染的简单方法
- C++套接字客户端到 Python 服务器未创建连接
- 用于解析 win64 堆栈跟踪的命令行客户端(可以访问符号服务器)
- 用于处理许多客户端 c++ 的分叉服务器
- 如何使用TCP / IP在c ++中同时将许多矩阵从服务器发送到客户端,反之亦然