public final class BonjourPublisher

  1. Object
  2. BonjourPublisher

Advertises a Bonjour / mDNS service on the local network.

A publisher registers a service of a given type and port; once registered any client on the same network running BonjourBrowser.browse(type, ...) will see it. txt records carry small key/value metadata (typical limit 255 bytes per value).

Example – advertise an HTTP service on port 8080

BonjourPublisher pub = BonjourPublisher.publish(
        "MyServer", "_http._tcp.", 8080, null);

// when shutting down
pub.unpublish();

On iOS the build pipeline appends type to NSBonjourServices in Info.plist automatically when this class is referenced; without that entry iOS 14+ silently rejects the publish.

Methods

public static BonjourPublisher publish(String name, String type, int port, Map<String, String> txt)Publishes a new service.
public String getName()
public String getType()
public int getPort()
public void unpublish()Removes the advertisement.

Inherited methods

Method details

publish

public static BonjourPublisher publish(String name, String type, int port, Map<String, String> txt)
Publishes a new service. name is shown to humans browsing services and must be unique on the local subnet; the OS may append a suffix to resolve collisions. type is the mDNS type (e.g. _http._tcp.). port is the listening port on this device. txt may be null or a String->String map of metadata.

getName

public String getName()

getType

public String getType()

getPort

public int getPort()

unpublish

public void unpublish()
Removes the advertisement. Idempotent.