Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

possible to send multicast packet out from multiple interfaces?  RSS feed

 
Dan Peters
Greenhorn
Posts: 10
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm looking for suggestions on how I can improve my application's 'auto-discovery' between server and clients.

I'm using multicast for 'auto-discovery': the server regularly sends out an 'announce' packet on a given multicast group address. The clients then join this multicast group, receive the packet, and pull the source IP address which is used to establish a TCP connection with the server.

This is working fine when the server and clients each only have one NIC, but I'm seeing the following problems:

*When the server has more than one interface, it's only sending the multicast UDP packet on the interface with default route. This results in all the clients on other subnets on other interfaces not getting the announce.
*Similar problem on the clients - they only seem to be listening on the interface with default route. Also, if a client attempts to join the multicast group and there is no default route defined on the system, the join fails.

I'm not an expert on multicast by any means, but I have been reading up on it to understand what's going on, and I can understand the behaviour: if the multicast group isn't explicitly defined in the system's routing table, then it has to have a default route so it can send the packets 'that-a-way' so they'll hopefully eventually reach their intended recipients.

So what can I do here? Ideally, I'd like to have the server announcement sent out on all subnets of all active interfaces - what's the best way to do that? Should I be looking at broadcasting on all subnets, or is multicast the best way to go here?

I should also mention that the 'auto-discovery' is intended for a LAN scenario - it really shouldn't be passing over any routers; I have an option on the client to manually specify the server's IP address in such a case.
 
Dan Peters
Greenhorn
Posts: 10
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My apologies if I was too verbose/vague in my OP. Basically, I'm wondering if there is a way to send multicast from more than one interface, or is a better approach to iterate through all the bound IP addresses and send a broadcast on each subnet? Any help is appreciated!
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Multicast is a feature of the network meaning when you write to a multicast group, the network switch will forward that packet to all interested parties on the multicast group, which is on the same subnet. Higher end network switches can forward multicast packets across a WAN (along with maintaining the membership lists), but I digress...

Anyway, it is highly unlikely that you have a multi-homed machine, where the NICs are going to the same subnet, so ... yeah, if you have a machine with multiple NICs and you need to write to a multicast group on all the NICs, which is likely going to different places, you will have to create a MulticastSocket for each NIC, iterate through to join the group, and write the packet.

Henry
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dan Peters wrote:My apologies if I was too verbose/vague in my OP. Basically, I'm wondering if there is a way to send multicast from more than one interface, or is a better approach to iterate through all the bound IP addresses and send a broadcast on each subnet? Any help is appreciated!


BTW, what do you mean by "bound IP" address? Are you referring to NIC bonding*? If so, you can ignore the component NICs, and just write to the bonded virtual NIC.

Henry


* I am thinking that you are not referring to NIC bonding, as you mentioned that they are going to different subnets.
 
Dan Peters
Greenhorn
Posts: 10
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Henry, thanks for your response!

No, I'm not talking about bonding, sorry if I was unclear:-)

So your suggestion got me thinking that the behavior I'm seeing (of joingroup failing if there is no default route defined) is by design in the Java layer.

I did some exploratory coding and found the following:

*When I create a MulticastSocket and don't specify the interface, it seems Java tries to do some intelligent work for me and assumes I want the default route, so if there is none then as I said the joingroup fails, but:

*When I create a MulticastSocket and specify the interface, then I can joingroup on that socket without problem. I guess by explicitly choosing the interface, Java assumes I know what I'm doing and just lets me.

So the solution I ended up with is, on both the master and clients, I iterate through interfaces, and explicitly send or listen on each. Tested it and now the server is picking up clients from various subnets on different interfaces. Awesome!

Thanks again.
 
Henry Wong
author
Sheriff
Posts: 23283
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Glad you figure it out. And thanks for coming back here to report on the solution/answer -- you earned a cow.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!