# Class BonjourBrowser

java.lang.Object
com.codename1.io.bonjour.BonjourBrowser

public final class BonjourBrowser extends java.lang.Object

Browses the local network for Bonjour / mDNS services.

Bonjour ("zeroconf" / "mDNS-SD") lets clients find network services -- a printer, a music server, another instance of your app -- without knowing their IP address in advance. Services are advertised under a type such as `_http._tcp.` or your own private `_myapp._tcp.`. A `BonjourBrowser` watches for services of one type and notifies the listener whenever a service comes online or goes away.

##### Platform support

- Android: `android.net.nsd.NsdManager`.
- iOS: `NSNetServiceBrowser` + `NSNetService`. The build pipeline injects `NSLocalNetworkUsageDescription` and the service type into `NSBonjourServices` so iOS 14+ doesn't block discovery.
- Simulator: JmDNS is used when present on the classpath; otherwise discovery is a no-op and the listener is told the platform is unsupported.

##### Example

    BonjourBrowser browser = BonjourBrowser.browse("_http._tcp.", new BonjourServiceListener() {
        public void onServiceResolved(BonjourService s) {
            Log.p("Found " + s.getName() + " at " + s.getHost() + ":" + s.getPort());
        }
        public void onServiceLost(BonjourService s) { /* ... */ }
        public void onBrowseError(Throwable t) { Log.e(t); }
    });

    // when finished
    browser.stop();

- ## Method Summary

  Modifier and Type
  Method
  Description
  `static BonjourBrowser`
  `browse(String type, BonjourServiceListener listener)`
  Starts browsing for `type` and returns a handle to stop the search.
  `String`
  `getType()`
  The service type passed to `browse(...)`.
  `static boolean`
  `isSupported()`
  `true` if the platform implements Bonjour at all.
  `void`
  `stop()`
  Stops this browser.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Method Details

  - ### browse

    public static BonjourBrowser browse(String type, BonjourServiceListener listener)
    Starts browsing for `type` and returns a handle to stop the search. `type` must be in mDNS form, e.g. `_http._tcp.` (trailing dot optional). `listener` is invoked on the EDT.

  - ### isSupported

    public static boolean isSupported()
    `true` if the platform implements Bonjour at all.

  - ### getType

    public String getType()
    The service type passed to `browse(...)`.

  - ### stop

    public void stop()
    Stops this browser. Idempotent.