467,077 Members | 1,172 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,077 developers. It's quick & easy.

Multicast on only one of two networks

I have a computer with two network cards (attached to seperate networks) and
I am having trouble getting my C# application to send its multicast packets
on a specific one. It receives just fine (I'm assuming because its listening
to both networks), but it seems like it just picks the default to send over.

I have implemented the MulticastOption(RemoteIP, LocalIP), but it doesn't
seem to be changing the interface it sends over.

Here's some of my code:
public void setupSocket()
{
localEP = new IPEndPoint(localIP, localPort);
incomingEP = new IPEndPoint(IPAddress.Any, 0);

sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram,
ProtocolType.Udp);
sock.Bind((EndPoint)localEP);
if(multicast)
{
mcEP = new IPEndPoint(mcIP, localPort);
MulticastOption mcastOption = new MulticastOption(mcIP, localIP);
sock.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.AddMembership, mcastOption);
sock.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.MulticastTimeToLive, 2);
//sock.SetSocketOption(SocketOptionLevel.IP,
SocketOptionName.MulticastInterface, <??? What goes here, its listed as a
byte []. but what is its value!???>);

//sock.Connect(mcEP); // Doesn't work in multicast, use sendto()
}
else
{
remoteEP = new IPEndPoint(remoteIP, remotePort);
sock.Connect(remoteEP);
}
}
public void receive()
{
EndPoint inEP = (EndPoint)incomingEP;
Byte[] buffer = new Byte[1024];
int size = sock.ReceiveFrom(buffer, ref inEP);
}
public void send(Byte[] buffer)
{
// if multicast
if(mcEP != null)
{
//client.Send(buffer, buffer.Length, mcEP);
//sock.Send(buffer);
sock.SendTo(buffer, mcEP);
}
else
{
sock.Send(buffer);
}
}
In addition, it seems to send O.K. when I send unicast. It doesn't work
when I try to do sock.connect(...) while using multicast. Any help would be
much appreciated! Thanks!

Nov 16 '05 #1
  • viewed: 4462
Share:
6 Replies
Hi teeks,
. Regarding on the issue, I am
finding proper resource to assist you and we will update as soon as posible.

Regards,

Steven Cheng
Microsoft Online Support

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

Nov 16 '05 #2
Hi,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you are having trouble to send data
over a particular network adapter. If there is any misunderstanding, please
feel free to let me know.

Based on my research, this issue might be caused by incorrect binding to
network adapters. When a Socket is binded to an IP address of Any or 0 as
value, it will select the network adapter automatically. By default, it
chooses the default one to send over. That might be the point you're
suffering from.

So please check localEP objected to see the value passed in. It shouldn't
be 0 or something like 127.0.0.1.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #3
You are correct. As far as I can tell the problem is in sending data over a
particular network adapter.

I have verified that the localIP that I start with is correct for the
particular network I wish to use, (the Address and m_Address values are both
0x14B3E05). This continues when I create the localEP. It also continues
when I cast it to an EndPoint and bind to the sock
(sock.LocalEndPoint.Adddress and sock.m_LocalEndPoint.Address, etc).

Nothing much has changed in all this.

Do I need to do anythign with the SetSocketOption(... ,
SocketOptionName.MulticastInterface, ...). I can't figure out what the third
argument should be if I do need it. Thanks!
"Kevin Yu [MSFT]" wrote:
Hi,

First of all, I would like to confirm my understanding of your issue. From
your description, I understand that you are having trouble to send data
over a particular network adapter. If there is any misunderstanding, please
feel free to let me know.

Based on my research, this issue might be caused by incorrect binding to
network adapters. When a Socket is binded to an IP address of Any or 0 as
value, it will select the network adapter automatically. By default, it
chooses the default one to send over. That might be the point you're
suffering from.

So please check localEP objected to see the value passed in. It shouldn't
be 0 or something like 127.0.0.1.

If anything is unclear, please feel free to reply to the post.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #4
Hi,

If you're trying to Multicast, I think you have to use SetSocketOption
method. Please check the following link for more information.

http://support.microsoft.com/?id=318911

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #5
Yeah, I've seen that example. I don't know what index is though. All I can
find out is that it's a byte array. Is it a string like "1.75.81.5" or is it
index[0] = 1, index[1] = 75, index[2] = 81, index[3] = 5, or is it something
like "Local Area Connection 2"???

Thanks for your help so far :-)

"Kevin Yu [MSFT]" wrote:
Hi,

If you're trying to Multicast, I think you have to use SetSocketOption
method. Please check the following link for more information.

http://support.microsoft.com/?id=318911

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #6
Hi,

Since SetSocketOption method has several overloads, the optionValue can be
an int, a byte array or an object like MulticastOption object. It can also
be a value from converted by IPAddress.HostToNetworkOrder and depends on
the option you need to set. But there is no overload which accepts a string.

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 16 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Ron Vecchi | last post: by
2 posts views Thread by Jim H | last post: by
5 posts views Thread by GVN | last post: by
7 posts views Thread by pietro.cerutti@gmail.com | last post: by
1 post views Thread by Jayme.Pechan | last post: by
reply views Thread by Stodge | last post: by
9 posts views Thread by raylopez99 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.