首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VC/MFC >

这样收发UDP数据包可以吗?该如何解决

2012-01-21 
这样收发UDP数据包可以吗?C/C++ codeint nRet, nLeft, nIdxnLeft 10nIdx 0while ( nLeft 0 ){nRe

这样收发UDP数据包可以吗?

C/C++ code
int nRet, nLeft, nIdx;nLeft = 10;nIdx = 0;while ( nLeft > 0 ){    nRet = sendto( s, buf+nIdx, nLeft, 0, (struct sockaddr *)&to, sizeof(to) );    if ( SOCKET_ERROR == nRet )    {        break;    }    nLeft -= nRet;    nIdx += nRet;}nLeft = 10;nIdx = 0;while ( nLeft > 0 ){    nRet = recvfrom( s, buf+nIdx, nLeft, 0, NULL, NULL );    if ( SOCKET_ERROR == nRet )    {        break;    }    nLeft -= nRet;    nIdx += nRet;}


[解决办法]
应该可以实现
while ( nLeft > 0 )
{
。。。
}
应该只会执行一次,除非你的包大于1480字节

热点排行