Phourm 2006年05月08日
在SmartPhone 2003上使用recvfrom函数,参数MSG_PEEK为什么返回WSAEOPNOTSUPP?
UDP为什么使用MSG_PEEK参数就出错,而用0做Flag就正常!
MSDN上没有说CE不支持MSG_PEEK啊!
有哪位知道怎么回事有?
下面是代码

#include <stdio.h>
#include "winsock2.h"


int _tmain(int argc, _TCHAR* argv[])
{
WSADATA wsaData;
SOCKET RecvSocket;
sockaddr_in RecvAddr;
int Port = 27015;
char RecvBuf[1024];
int BufLen = 1024;
sockaddr_in SenderAddr;
int SenderAddrSize = sizeof(SenderAddr);

//-----------------------------------------------
// Initialize Winsock
WSAStartup(MAKEWORD(2,2), &wsaData);

//-----------------------------------------------
// Create a receiver socket to receive datagrams
RecvSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);

//-----------------------------------------------
// Bind the socket to any address and the specified port.
RecvAddr.sin_family = AF_INET;
RecvAddr.sin_port = htons(Port);
RecvAddr.sin_addr.s_addr = htonl(INADDR_ANY);

bind(RecvSocket, (SOCKADDR *) &RecvAddr, sizeof(RecvAddr));

//-----------------------------------------------
// Call the recvfrom function to receive datagrams
// on the bound socket.
printf("Receiving datagrams...\n");
int nreceived = recvfrom(RecvSocket,
RecvBuf,
1,
MSG_PEEK,
(SOCKADDR *)&SenderAddr,
&SenderAddrSize);
/*就是这里总是返回-1*/
if (nreceived == -1)
::WSAGetLastError();//错误码10045

//-----------------------------------------------
// Close the socket when finished receiving datagrams
printf("Finished receiving. Closing socket.\n");
closesocket(RecvSocket);

//-----------------------------------------------
// Clean up and exit.
printf("Exiting.\n");
WSACleanup();

return 0;
}
...全文
177 点赞 收藏 3
写回复
3 条回复

还没有回复,快来抢沙发~

发动态
发帖子
Windows客户端开发
创建于2007-08-27

6818

社区成员

1.8w+

社区内容

Windows Phone是微软发布的一款手机操作系统,它将微软旗下的Xbox LIVE游戏、Zune音乐与独特的视频体验整合至手机中。
社区公告
暂无公告