Using MulticastInterface SocketOption

  • Thread starter Thread starter Tom Kent
  • Start date Start date
T

Tom Kent

I was wondering if someone could give me an example of how to correctly use
the MulticastInterface with sock.SetSocketOption(). I found it listed in
the enums for the socket options
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/cpref/html/frlrfsystemnetsocketssocketoptionnameclasstopic.asp
and it sounded like what I needed. I have 2 nics and I want to multicast
only on the one connected to that specific network.
Thanks,
Tom
 
(e-mail address removed) ("Peter Huang") wrote in
Hi Tom,

Here is a KB article, you may take a look to see if that is what you
want. HOW TO: Use SetSocketOption() with MulticastInterface OptionName
in Visual Studio .NET (318911)
http://support.microsoft.com/default.aspx?scid=KB;EN-US;318911

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no
rights.


That's not much of an excuse....it doesn't tell us what the argument is, it
just gets what someone types from the command prompt.

I have however found that this works:

setupSocket(IPAddress localIP, IPAddress mcIP, int port)
{
mcEP = new IPEndPoint(mcIP, port);
MulticastOption mcastOption = new MulticastOption(mcIP, localIP);
sock.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.AddMemebership, mcastOption);
sock.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.MulticastInterface, (int)localIP.Address);
}

It's that (int)locapIP.Address that was key to figuring this out. I don't
know if its possible, but someone might update that KB article to include
something like this...so we know what it is that's needed.
Thanks,
Tom
 
Hi,

I am sorry that I have somewhat confusion with your question.
But I am glat that you have found the solution yourself.
If you still have any concern on this issue, please feel free to post here
and we will follow up with you.


Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
 
I have the same problem as Tom except I can't use the
IPAddress.Address method he recommended since that is an
obsolete method in .net Framwork 1.1.

Is there another way to use the MulticastInterface
SocketOption. It would be best if I could specifiy my
local IP address instead of an integer as the value for
MulticastInterface (The same way that it is done for
Addmembership).

/Peter
 
Hi Tom!
I have the same problem as you except I can't use the
IPAddress.Address method you recommend since that is an
obsolete method in .net Framwork 1.1.

Have you found another way to solve this?

/Peter
 
I have the same problem as Tom except I can't use the
IPAddress.Address method he recommended since that is an
obsolete method in .net Framwork 1.1.

Is there another way to use the MulticastInterface
SocketOption. It would be best if I could specifiy my
local IP address instead of an integer as the value for
MulticastInterface (The same way that it is done for
Addmembership).

/Peter
 
Hi Peter,
I have the same problem as Tom except I can't use the
IPAddress.Address method he recommended since that is an
obsolete method in .net Framwork 1.1.

Is there another way to use the MulticastInterface
SocketOption. It would be best if I could specifiy my
local IP address instead of an integer as the value for
MulticastInterface (The same way that it is done for
Addmembership).

This is the non-obsolet a.Address equivalent:

BitConverter.ToInt32(a.GetAddressBytes(), 0);

It only works for IPv4.

bye
Rob
 
Hi Peter,


This is the non-obsolet a.Address equivalent:

BitConverter.ToInt32(a.GetAddressBytes(), 0);

It only works for IPv4.

bye
Rob

That would work...i found that the a.Address does work, even being
obsolete.

Anyway, i've got all my stuff working :-)
 
Back
Top