I'm finally using the BeginReceive method(async), and I'm giving as context the ip on which it's bound
Get the IpAddress on which we received an UDP Multicast request
-
18-03-2022 - |
Question
I'm using an UdpClient
to read data from a multicast group.
It's configured like this:
m_udpClientReceiver = new UdpClient();
m_receivingEndPoint = new IPEndPoint(IPAddress.Any, m_port);
m_udpClientReceiver.ExclusiveAddressUse = false;
m_udpClientReceiver.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
m_udpClientReceiver.ExclusiveAddressUse = false;
m_udpClientReceiver.Client.Bind(m_receivingEndPoint);
m_udpClientReceiver.JoinMulticastGroup(m_multicastAddress, 255);
and I read it with:
Byte[] data = m_udpClientReceiver.Receive(ref m_receivingEndPoint);
I've several network cards(two LAN, one wifi), that are bound on differents subnets. I need to know on which network card(which ip in fact) the request has been received.
How can I achieve this?
Thank you!
Solution 2
OTHER TIPS
As an alternative have you considered not joining a multicast group? You can send and receive multicast packets just as easily using the standard UDPClient class. i.e.
UdpClient.Send(byte[] dgram, int bytes, IPEndPoint endPoint)
where endPoint = new IPEndPoint(IPAddress.Broadcast, <port number>)
. And on the receive still using:
Byte[] data = m_udpClientReceiver.Receive(ref m_receivingEndPoint);
where m_receivingEndPoint is now correctly set? I've just tested this and it works fine.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow