Skip to content

A very simple pure Java implementation of Multicast DNS SD (Service Discovery)

License

Notifications You must be signed in to change notification settings

faceless2/zeroconf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Zeroconf

Zeroconf is a simple Java implementation of Multicast DNS Service Discovery, aka the service discovery bit of Zeroconf. Originally written as a quick hack to avoid having to use https://github.com/jmdns/jmdns, it has evolved into something that can both announce and listen for Services:

Here's a simple example which announces a service on all interfaces on the local machine:

import com.bfo.zeroconf.*;

Zeroconf zc = new Zeroconf();
Service service = new Service.Builder()
                    .setName("MyWeb")
                    .setType("_http._tcp")
                    .setPort(8080)
                    .put("path", "/path/to/service")
                    .build(zc);
service.announce();
// time passes
service.cancel();
// time passes
zc.close();

And to listen, either add a Listener for events or use the live, thread-safe Collection of Services.

import com.bfo.zeroconf.*;

Zeroconf zc = new Zeroconf();
zc.addListener(new ZeroconfListener() {
    public void serviceNamed(String type, String name) {
        if ("_http._tcp".equals(type)) {
            zc.query(type, name);  // Ask for details on any announced HTTP services
        }
    }
    public void serviceAnnounced(Service service) {
        // A new service has just been announced
    }
});

zc.query("_http._tcp", null); // Ask for any HTTP services

// time passes
for (Service s : zc.getServices()) {
  if (s.getType().equals("_http._tcp") {
     // A service has been announced at some point in the past, and has not yet expired.
   }
}

// time passes
zc.close();

To build

Run ant to build the Jar in the build directory, and javadoc in the doc directory.

About

A very simple pure Java implementation of Multicast DNS SD (Service Discovery)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages