UDPClient Multicast receive fails on computer with multiple NICs

蹲街弑〆低调 提交于 2019-12-05 10:51:37
karl

I had the same issue found this post, then found the solution at: UDP: Read data from all network interfaces

Basically Bind() to 0.0.0.0 doesn't work and you have to Bind() and JoinMulticastGroup() on every local ip address. Gotta love Microsoft for this one.

The interface part is the important part in the following code:

unsigned long interface;
ip_mreq mreq;

_parseHostname( _description->getInterface(), interface );
mreq.imr_multiaddr.s_addr = _writeAddress.sin_addr.s_addr;
mreq.imr_interface.s_addr = interface;

setsockopt( _readFD, IPPROTO_IP, IP_ADD_MEMBERSHIP,
                (char*)&mreq, sizeof( mreq ));

With interface being the (unicast) IP address of the receive network card.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!