G
Guest
Hi guys!
I have several IP addresses defined on my PC (all bound to the same
interface), and i need to send multicast messages from a specific address.
Here's my code:
void SendMsg( string localAddr, int localPort, string destAddr, int
destPort, byte[] body )
{
Socket sock = new Socket( AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp );
sock.Bind( new IPEndPoint( IPAddress.Parse( localAddr ), localPort ) );
sock.SendTo( body, new IPEndPoint( IPAddress.Parse( destAddr ), destPort
) );
sock.Close();
}
The problem is - if "destAddr" contains a multicast address, than no matter
what address i pass as "localAddr" parameters, the messages are always sent
from the same address, randomly chosen from among the addresses defined on my
PC.
How can i bind my outgoing multicast messages to a particular address?
Thanks!
p.s.: i've seen suggestions to use "MulticastInterface" socket option in
order to solve this problem. However, this only affects the interface, via
which the messages are sent, but not the address (as i said, i have several
addresses defined over one interface).
I have several IP addresses defined on my PC (all bound to the same
interface), and i need to send multicast messages from a specific address.
Here's my code:
void SendMsg( string localAddr, int localPort, string destAddr, int
destPort, byte[] body )
{
Socket sock = new Socket( AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp );
sock.Bind( new IPEndPoint( IPAddress.Parse( localAddr ), localPort ) );
sock.SendTo( body, new IPEndPoint( IPAddress.Parse( destAddr ), destPort
) );
sock.Close();
}
The problem is - if "destAddr" contains a multicast address, than no matter
what address i pass as "localAddr" parameters, the messages are always sent
from the same address, randomly chosen from among the addresses defined on my
PC.
How can i bind my outgoing multicast messages to a particular address?
Thanks!
p.s.: i've seen suggestions to use "MulticastInterface" socket option in
order to solve this problem. However, this only affects the interface, via
which the messages are sent, but not the address (as i said, i have several
addresses defined over one interface).