This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes UDP broadcast on multiple interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "UDP broadcast on multiple interfaces" Watch "UDP broadcast on multiple interfaces" New topic
Author

UDP broadcast on multiple interfaces

Suparn Gupta
Greenhorn

Joined: Feb 26, 2012
Posts: 16
Hello all!
My machine has 3 network adapters. it is connected to other machines via all those three adapters. Each connection is a different subnet. So in total I have my machine connected to three subnets. Now I want to broadcast a UDP packet to other machines. When I do so, the broadcast packet goes only from one network interface instead of all the three. I know I can bind the specific network adapter address to a socket but I want only one socket to control the communication. How can I broadcast UDp packets through all the three interfaces using only one socket bound to a port say 5000?
Please help me!
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1280

Hi,

what do you mean by "broadcast packet"? Do you use a broadcast address or do you just want to send the packet out on all interfaces of your machine? Depending on the underlying OS and configuration I suspect your problem isn't even a problem in the application. Usually the OS decides based on routing table entries to which interfaces a network packet should be sent. This way the interfaces bound to other address ranges/subnets don't even see packets when the OS "knows" (from the routing table) that the receiver is only reachable via another interface. But it's hard to give good advices without knowing more details. Maybe it would be a good idea to tell us what problem you are trying to solve this way ;-)

Marco
Suparn Gupta
Greenhorn

Joined: Feb 26, 2012
Posts: 16
Hi Marco,

Actually I am developing a java program that should send a broadcast packet out of all its interfaces to the other machines attached to it by using the subnet broadcst address for each interface. When those remote machines receive the packet, they return their IP address and some information related to them.

UPDATE: I have one more problem, when I try to get the broadcast address using interfaceAddress.getBroadcast(), it gives me 255.255.255.255. This should return the subnet broadcast address like 10.0.0.3 (subnet mask /30, network id 10.0.0.0, hosts are connected as 10.0.0.1, 10.0.0.2)
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Suparn Gupta wrote:How can I broadcast UDp packets through all the three interfaces using only one socket bound to a port say 5000?


You can't. You'd have to create one DatagramSocket for each interface, using the c'tor that takes a SocketAddress.
Suparn Gupta
Greenhorn

Joined: Feb 26, 2012
Posts: 16
Thanks Marco!

I got it working. i am so Happy!!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: UDP broadcast on multiple interfaces
 
Similar Threads
Multicast UDP Packet Loss
How to make a Serverless java LAN Chat application with a user list
some java interview Questions
Multichat Application
TCP or UDP