jacknad
jacknad

Reputation: 13739

How to enable UDP/IP broadcast programmatically?

I need to broadcast a UDP/IP query but broadcast is typically not enabled by default. How do I enable UDP/IP broadcast? I am adding the capability to my application to search for Lantronix XPort IP addresses as described here, but was concerned that my approach would fail on systems in the field where UDP broadcast is not enabled. I suspect there is some java class that enables UDP broadcast with perhaps one line of code, but have no clue what it might be called.

Upvotes: 0

Views: 820

Answers (2)

jacknad
jacknad

Reputation: 13739

Found answer here. This is what I did:

if (!discoverySocket.getBroadcast()) discoverySocket.setBroadcast(true);

Upvotes: 1

Peter Lawrey
Peter Lawrey

Reputation: 533870

UDP broadcast is enabled on every Windows and Linux system I have heard of (and I have work on a few) The trick is usually how to turn it off.

What you may have a problem with is broadcast at the network level. This is usually turned off by the router to stop broadcast messages going uncontrolled across the network. Note: broadcast is limited to you local LAN in any case.

You may need multi-cast instead but your network still has to be configured to allow it.

Upvotes: 1

Related Questions