BCB winsock编程 UDP 发送

xuxuhaha 2016-02-22 11:33:02
我在BCB中用套接字发送了一点数据,但是抓包的时候没抓到,控件是NMUDP控件,是不是要调用一下控件呀,但是该怎么调用呢?
下面是sock编程代码:

WSADATA wsaData = {0};
WORD wVer = MAKEWORD(2,2);
int nRet = WSAStartup(wVer,&wsaData);

SOCKET hSocket = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);

saServer.sin_family = AF_INET;
saServer.sin_port = htons(60020);
saServer.sin_addr.S_un.S_addr = inet_addr("192.168.4.255");
int iRet= sendto(hSocket,buf,strlen(buf),0,(SOCKADDR*)&saServer,sizeof(saServer));
closesocket(hSocket);
...全文
134 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
zcchm 2016-03-03
  • 打赏
  • 举报
回复
https://msdn.microsoft.com/zh-cn/library/ms740120(en-us,VS.85).aspx If no incoming data is available at the socket, the recvfrom function blocks and waits for data to arrive according to the blocking rules defined for WSARecv with the MSG_PARTIAL flag not set unless the socket is nonblocking. In this case, a value of SOCKET_ERROR is returned with the error code set to WSAEWOULDBLOCK. The select, WSAAsyncSelect, or WSAEventSelect can be used to determine when more data arrives.
xuxuhaha 2016-02-22
  • 打赏
  • 举报
回复
这个问题解决了,是因为发送的地址和我的本机IP不在同一网段,我改成广播权限打开就能发送了。然后我改成了广播地址255.255.255.255,wirshark 抓包看到返回了好多不同IP地址的设备信息,但是,接收函数死在那里了,后面是这么写的: if(iRet > 0) iRet = recvfrom(hSocket,bufrecv,1024,0,NULL,NULL); 请问为什么会死在这里呀

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧