扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:佚名 来源:论坛 2007年10月20日
关键字:
SOCKADDR_IN addrLocal; // We want to use the Internet address family addrLocal.sin_family = AF_INET; // Use any local address addrLocal.sin_addr.s_addr = INADDR_ANY; // Use arbitrary port - but the same as on other clients/servers addrLocal.sin_port = htons(uiPort); // Bind socket to our address if(SOCKET_ERROR == bind(hUDPSocket, (LPSOCKADDR)&addrLocal, sizeof(struct sockaddr))) { cout << "Euston, we have a problem"; } // Ready to switch to multicasting mode |
int WSAAPI setsockopt(SOCKET s, int level, int optname, const char FAR * optval, int optlen); |
struct ip_mreq { struct in_addr imr_multiaddr; /* multicast group to join */ struct in_addr imr_interface; /* interface to join on */ } |
struct ip_mreq mreq; mreq.imr_multiaddr.s_addr = inet_addr("234.5.6.7"); mreq.imr_interface.s_addr = INADDR_ANY; nRet = setsockopt(hUDPSocket, IPPROTO_IP, IP_ADD_MEMBERSHIP,(char*)&mreq, sizeof(mreq)); |
SOCKADDR_IN addrSrc; nRet = recvfrom(hUDPSocket, (char *)&Data, sizeof(Data), 0, (struct sockaddr*)&addrSrc, sizeof(addrSrc)); |
nRet = setsockopt(hUDPSocket, IPPROTO_IP, IP_DROP_MEMBERSHIP, (char*)&mreq, sizeof(mreq)); |
char TTL = 32 ; // Restrict to our school network, for example setsockopt(hUDPSocket, IPPROTO_IP, IP_MULTICAST_TTL, (char *)&TTL, sizeof(TTL)); |
SOCKADDR_IN addrDest; szHi[50]; addrDest.sin_family = AF_INET; // Target multicast group address addrDest.sin_addr.s_addr = inet_addr("234.5.6.7"); // Port on which client is set to receive data packets addrDest.sin_port = htons(uiPort); // Something unoriginal to send strcpy(szHi,"Hello Multicast Group!"); nRet = sendto(hUDPSocket, (char *)szHi, sizeof(szHi), 0, (struct sockaddr*)&addrDest, sizeof(addrDest)); |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者