我试图使用下面的代码发送UDP,但是我得到了奇怪的结果。
if((sendto(newSocket, sendBuf, totalLength, 0, (SOCKADDR *)&sendAddr, sizeof(sendAddr)) == bytesSent) < 0)
{
printf("Send error! - %d\n", WSAGetLastError());
}但是,假设当totalLength变量设置为30时,sendto函数实际上返回2292556,那么它是否应该至少返回30左右的值?在使用sendto之前,我检查了totalLength变量,它会很高兴地返回一个我同意的值,但随后sendto会返回一个很大的值。总长度永远不会大于实际的缓冲区大小。
WSAGetLastError只返回0。
谢谢。
发布于 2009-11-24 05:03:41
我认为您的问题是条件的== bytesSent) < 0)部分。这应该是类似if (( bytesSent = sendto( ... )) < 0 )的东西吗?
发布于 2012-03-24 17:33:24
您正在检查是否发送到(...)等于bytesSent,而不是可能等于bytesSent=sendto
https://stackoverflow.com/questions/1785904
复制相似问题