WSASendTo的回调函数问题

ygh2008123 2010-09-30 07:33:56
使用的是UDP组播,overlap方式发送,调用了WSASendTo后错误代码是WSA_IO_PENDING,本机上接收端也能收到发出去的数据,但发送端就是没进入回调函数,不知为何,麻烦各位帮忙看看

socket 设置如下:
m_hSocket = WSASocket (
AF_INET,
SOCK_DGRAM,
0,
NULL,
0,
WSA_FLAG_MULTIPOINT_C_LEAF | WSA_FLAG_MULTIPOINT_D_LEAF | WSA_FLAG_OVERLAPPED) ;

if (m_hSocket == INVALID_SOCKET) {
goto JoinFail ;
}

t = TRUE ;
i = setsockopt (
m_hSocket,
SOL_SOCKET,
SO_REUSEADDR,
(char *) & t,
sizeof t
) ;
if (i == SOCKET_ERROR) {
goto JoinFail ;
}

ZeroMemory (& saddr, sizeof saddr) ;
saddr.sin_family = AF_INET ;
saddr.sin_port = usPort ; // want data on this UDP port
saddr.sin_addr.S_un.S_addr = INADDR_ANY ; // don't care about NIC we're bound to

i = bind (
m_hSocket,
(LPSOCKADDR) & saddr,
sizeof saddr
) ;
if (i == SOCKET_ERROR) {
goto JoinFail ;
}

i = setsockopt (
m_hSocket,
IPPROTO_IP,
IP_MULTICAST_TTL,
(char *) & ulTTL,
sizeof ulTTL
) ;
if (i == SOCKET_ERROR) {
goto JoinFail ;
}

i = setsockopt (
m_hSocket,
IPPROTO_IP,
IP_MULTICAST_IF,
(char *) & ulNIC,
sizeof ulNIC
) ;
if (i == SOCKET_ERROR) {
goto JoinFail ;
}
-----------------------------------------------
WSASendTo的调用如下:
LPWSAOVERLAPPED pOverlap = new WSAOVERLAPPED;
pOverlap->Internal = 0;
pOverlap->InternalHigh = 0;
pOverlap->OffsetHigh = 0;
pOverlap->Offset = 0;
pOverlap->hEvent = (HANDLE)pParam; //回调函数使用该参数

DWORD sendbytes;
i= WSASendTo(m_hSocket,pParam->wsabuf,2,&sendbytes,0,(LPSOCKADDR) & m_saddrDest,sizeof m_saddrDest,pOverlap,SendComplete);
if (i != 0) {
dw = GetLastError () ;
if (dw != WSA_IO_PENDING)
{
return HRESULT_FROM_WIN32 (dw) ;
}
}
---------------------------------------------------------------
void CALLBACK SendComplete(
IN DWORD dwError,
IN DWORD cbTransferred,
IN LPWSAOVERLAPPED lpOverlapped,
IN DWORD dwFlags);

...全文
27 点赞 收藏 3
写回复
3 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
就是just4 2010-10-01
汗一个,楼主发错地方了,

直接C/C++版问下先,

等俺学会了网络编程再说,:)
回复
jackiedzc 2010-10-01
有空还来windows大阪,自己泡茶喝:)
回复
ygh2008123 2010-10-01
不常发帖,谢谢提醒
回复
相关推荐
发帖
windows网络管理与配置
创建于2007-08-02

6070

社区成员

windows网络管理与配置
申请成为版主
帖子事件
创建了帖子
2010-09-30 07:33
社区公告
暂无公告