+ -
当前位置:首页 → 问答吧 → 这样收发UDP数据包可以吗?

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

时间:2011-12-06

来源:互联网

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;
}

作者: MissionSuccess   发布时间: 2011-12-06

nRet = recvfrom( s, buf+nIdx, nLeft, 0, NULL, NULL );
你从哪里接收呢?

作者: agoago_2009   发布时间: 2011-12-06