Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make two Java applications on the same LAN aware of each other

I have a Java program running on two computers that are both on the same network. I would like to have these applications become aware of each other, so they could communicate directly as opposed to communicating with the server to relay messages.

I believe i may have a solution as to how this would work, but am unable to find any examples to compare my solution against. Do you guys know how this problem is usually solved?

like image 778
Dustin Gamester Avatar asked Dec 03 '25 09:12

Dustin Gamester


2 Answers

There is a good library that implements the Zeroconf / Bonjour standard in plain java at http://jmdns.sourceforge.net/

This basically relieves you from the protocol burden and allows you to advertise and lookup service providers based in logical names (That's what iTunes or Mac printing does for example).

This book http://www.amazon.com/Zero-Configuration-Networking-Definitive-Guide/dp/0596101007 explains all basic concepts.

like image 119
mtraut Avatar answered Dec 05 '25 23:12

mtraut


You could get them to do a UDP multicast within a LAN environment to identify the programs using protocol messages then have a stored cache of each other's identity and then use TCP to connect and do main exchanging of messages (which is more reliable than UDP). Or you can simply proceed with UDP messaging only if you want to.

You can search for multicasting in Java online.

Some multicast related links:

http://download.oracle.com/javase/1.4.2/docs/api/java/net/MulticastSocket.html

http://www.javafaq.nu/java-article817.html

A good multicast chat software you can reference:

http://sourceforge.net/projects/mc2/

like image 29
thotheolh Avatar answered Dec 05 '25 23:12

thotheolh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!