18,356
社区成员
发帖
与我相关
我的任务
分享
st_DDSClient.m_hSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (SOCKET_ERROR == st_DDSClient.m_hSocket)
{
return FALSE;
}
BOOL bReuse = TRUE;
if (SOCKET_ERROR == setsockopt(st_DDSClient.m_hSocket, SOL_SOCKET, SO_REUSEADDR, (char *)&bReuse, sizeof(BOOL)))
{
return FALSE;
}
int nLoop = 1;
if (SOCKET_ERROR == setsockopt(st_DDSClient.m_hSocket, IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&nLoop, sizeof(nLoop)))
{
DDS_IsErrorOccur = TRUE;
DDS_dwErrorCode = ERROR_HMC_NETENGINE_DDS_SUBSCRIBE_CREATEREAD_LOOP;
return FALSE;
}
st_DDSClient.st_SockAddr.sin_family = AF_INET;
st_DDSClient.st_SockAddr.sin_port = htons(st_DDSClient.st_DDSPublish.nPort);
st_DDSClient.st_SockAddr.sin_addr.s_addr = INADDR_ANY;
if (SOCKET_ERROR == bind(st_DDSClient.m_hSocket, (sockaddr *)&st_DDSClient.st_SockAddr, sizeof(st_DDSClient.st_SockAddr)))
{
return FALSE;
}
ip_mreq st_IPCast;
st_IPCast.imr_interface.s_addr = INADDR_ANY;
st_IPCast.imr_multiaddr.s_addr = inet_addr(st_DDSClient.st_DDSPublish.tszDDSAddr);
if (SOCKET_ERROR == setsockopt(st_DDSClient.m_hSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&st_IPCast, sizeof(st_IPCast)))
{
return FALSE;
}
recvfrom(st_DDSClient.m_hSocket, tszMsgBuffer, nRecvLen, 0, (sockaddr *)&st_RecvAddr, &nSize);//一直卡在这里,不动了