Class Discovery
java.lang.Object
com.codename1.backend.Discovery
Finds and is found on the local network over multicast DNS (Bonjour,
DNS-SD): the same records the client's BonjourBrowser and
BonjourPublisher read and write, so a phone app discovers a device's
backend with no address configured, and a device finds a gateway the same
way.
Discovery.Advertisement ad = Discovery.advertise("Hall Thermostat", "_thermo._tcp", 8080,
Collections.singletonMap("api", "/v1"));
Discovery.browse("_gateway._tcp", new Discovery.Listener() {
public void found(Discovery.Service s) { connect(s.getHost(), s.getPort()); }
public void lost(Discovery.Service s) { }
});
The protocol runs on one daemon thread, and listeners are called on it: a
server has no event dispatch thread, so a listener that does real work
hands it to a task. The thread exits when nothing is advertised or browsed.
A name another host already uses gets a numeric suffix, as Bonjour does;
Discovery.Advertisement.getName() says which name was taken. IPv4 only.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA running advertisement.static final classA running browse.static interfaceReceives what abrowse(String, Listener)finds.static final classA service seen on the network. -
Method Summary
Modifier and TypeMethodDescriptionstatic Discovery.AdvertisementAdvertises a service onport.static Discovery.Browsebrowse(String type, Discovery.Listener listener) Browses for a type untilDiscovery.Browse.close().
-
Method Details
-
advertise
-
browse
Browses for a type untilDiscovery.Browse.close().
-