Broadcast networking

Hi,

We're creating an application to do distributed measurement of application performance that runs on workstations and that we can deploy on our network.

We'd like for these "watchdog" PCs to announce themselves to the nearest data consolidation server.

So, what we'd like to do is have them do some sort of a broadcast to find the servers that exist and are available to receive the data they're collecting.

How would one write a "broadcast" network request (like ARP or a DHCP client request) to announce themselves.  We would know the "port" to use, but not the IP address to direct the message to (it should be anything that responds).

Any example code that does this would be even better.
LVL 1
Gene KlamerusTechnical ArchitectAsked:
Who is Participating?
 
k_suchdevaConnect With a Mentor Commented:
Broadcast packets are sent in UDP. You can use UDP classes in java and set the destincation as of the packet as x.y.z.255 and it should be broadcasted to the whole network.

Khem
0
 
CichaConnect With a Mentor Commented:
Hi

Use java.net.MulticastSocket
0
 
lExConnect With a Mentor Commented:
String broadcast = "..."; //depends on your network
int port = 1111;

String data = "...";
byte[] buf = data.getBytes();
DatagramSocket socket = new DatagramSocket();
DatagramPacket packet = new DatagramPacket(buf, buf.length,InetAddress.getByName(broadcast),port);
socket.send(packet);


//Packet will send to all computers in network to specified port.
0
 
CleanupPingCommented:
klamerus:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
TimYatesCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Split between k_suchdeva, Cicha and IEx

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TimYates
EE Cleanup Volunteer
0
All Courses

From novice to tech pro — start learning today.