TROZeroConfBrowser

Overview

The TROZeroConfBrowser class provides methods for receiving information about the ZeroConf environment and services registered in it.

Use Case

You can use this component in your client application when you need to discover services registered within ZeroConf service providers. You have to take the following steps to start using this class in your application: * Create an instance of the TROZeroConfBrowser component and set up its Domain property (set it to 'local.' for LAN). Also, set the ServiceType property to the full name of the service you want to browse for (i.e. '_bonjourdiscoverableservice_rosdk._tcp' ). * Add event handlers for the OnServiceAdded and OnServiceRemoved events to handle appearing/disappearing services, respectively. For example:

procedure TClientForm.ROZeroConfBrowserServiceAdded(
  Sender: TROZeroConfBrowser; aRecord: TROZeroConfService);
var host: string;
begin
  LogMessage('Discovered new service: ' + aRecord.ServiceName);

  if aRecord.TryResolve then 
  begin
    host := StringReplace(aRecord.HostTarget, LOCAL_SUFFIX, `, [rfIgnoreCase]);
    LogMessage(Format('Service resolved. Host name: %s Port number: %d',
                               [host, aRecord.Port]));
   end
   else 
   begin
     LogMessage('Service resolve failed!');
   end;
end;

procedure TClientForm.ROZeroConfBrowserServiceRemoved(
  Sender: TROZeroConfBrowser; aRecord: TROZeroConfService);
begin
  LogMessage(Format('Service has gone down: %s (at host %s:%d)',
                            [aRecord.ServiceName,
                             StringReplace(aRecord.HostTarget, LOCAL_SUFFIX, `, [rfIgnoreCase]),
                             aRecord.Port]));
end;
  • To start receiving information about registered/unregistered services, set the Active property of the TROZeroConfBrowser to true.

Note: Take a look at the Bonjour Discovery sample shipped with the Remoting SDK to see service discovery in action.

Location

 

constructor Create  override

Creates a new instance.

constructor Create(AOwner: TComponent)

Parameters:

  • AOwner: Owner.

Active

Determines if the service browser is currently active. By setting this property to true, you will initiate a service search, otherwise the Stop method will be called.

property Active: Boolean read write

Assign  override

Copies the contents of another, similar object.

procedure Assign(Source: TPersistent)

Parameters:

  • Source: Instance whose properties will be copied

BrowseAndResolve (integer, UnicodeString, Unicodestring, integer, unicodestring, string, TIpType): Boolean  overload

Forcibly browses for a service on the AHostTarget host. If the service is found, this method returns the information in the out parameters.

function BrowseAndResolve(aTimeout: integer; const AHostTarget: UnicodeString; out fullDomainName: Unicodestring; out port: integer; out txtRecord: unicodestring; out addresses: string; aIpType: TIpType): Boolean

Parameters:

  • aTimeout: Timeout (in seconds)
  • AHostTarget: Host target
  • fullDomainName: Full domain name
  • port: Port
  • txtRecord: Additional service information like channel, message type etc.
  • addresses: Address
  • aIpType: TIpType type value.

BrowseAndResolve (UnicodeString, Unicodestring, integer, unicodestring, string, TIpType): Boolean  overload

Forcibly browses for a service on the AHostTarget host. If the service is found, this method returns the information in the out parameters.

function BrowseAndResolve(const AHostTarget: UnicodeString; out fullDomainName: Unicodestring; out port: integer; out txtRecord: unicodestring; out addresses: string; aIpType: TIpType): Boolean

Parameters:

  • AHostTarget: Host target
  • fullDomainName: Full domain name
  • port: Port
  • txtRecord: Additional service information like channel, message type etc.
  • addresses: Address
  • aIpType: TIpType type value.

Domain    (declared in TROBaseZeroConf)

Represents the domain name in which the LAN or WLAN services will be discovered.

property Domain: Unicodestring read write

OnError

This event is raised when an error occurs during service browsing.

property OnError: TROZeroConfBrowserError read write
delegate: procedure OnError(Sender: TROZeroConfBrowser; const ACurrentEngine: TROZeroConfEngine; anException: Exception)

OnServiceAdded

Fires whenever a new service is found. The aRecord property will hold a reference to the TROZeroConfService that can be used to receive information about the discovered service.

property OnServiceAdded: TROZeroConfBrowserResultEvent read write
delegate: procedure OnServiceAdded(Sender: TROZeroConfBrowser; aRecord: TROZeroConfService)

OnServiceRemoved

Fires whenever a service is no longer available. The aRecord property will hold a reference to the TROZeroConfService that can be used to receive information about the service.

property OnServiceRemoved: TROZeroConfBrowserResultEvent read write
delegate: procedure OnServiceRemoved(Sender: TROZeroConfBrowser; aRecord: TROZeroConfService)

ROFreeNotification    (declared in TROComponent)

Forwards notification messages to all owned RO components.

procedure ROFreeNotification(AComponent: TComponent)

Parameters:

  • AComponent: component

RORemoveFreeNotification    (declared in TROComponent)

Disables destruction notification for specified RO component.

procedure RORemoveFreeNotification(AComponent: TComponent)

Parameters:

  • AComponent: component

ServiceType

Specifies the full name of the service you want to discover.

property ServiceType: Unicodestring read write

Stop

Cancels the service search.

procedure Stop

TriggerFailed  protected override

Executes the OnError event.

procedure TriggerFailed(const ACurrentEngine: TROZeroConfEngine; anException: Exception)

Parameters:

  • ACurrentEngine: Current engine
  • anException: Exception

 

Active

Determines if the service browser is currently active. By setting this property to true, you will initiate a service search, otherwise the Stop method will be called.

property Active: Boolean read write

Domain    (declared in TROBaseZeroConf)

Represents the domain name in which the LAN or WLAN services will be discovered.

property Domain: Unicodestring read write

ServiceType

Specifies the full name of the service you want to discover.

property ServiceType: Unicodestring read write

 

constructor Create  override

Creates a new instance.

constructor Create(AOwner: TComponent)

Parameters:

  • AOwner: Owner.

Assign  override

Copies the contents of another, similar object.

procedure Assign(Source: TPersistent)

Parameters:

  • Source: Instance whose properties will be copied

BrowseAndResolve (integer, UnicodeString, Unicodestring, integer, unicodestring, string, TIpType): Boolean  overload

Forcibly browses for a service on the AHostTarget host. If the service is found, this method returns the information in the out parameters.

function BrowseAndResolve(aTimeout: integer; const AHostTarget: UnicodeString; out fullDomainName: Unicodestring; out port: integer; out txtRecord: unicodestring; out addresses: string; aIpType: TIpType): Boolean

Parameters:

  • aTimeout: Timeout (in seconds)
  • AHostTarget: Host target
  • fullDomainName: Full domain name
  • port: Port
  • txtRecord: Additional service information like channel, message type etc.
  • addresses: Address
  • aIpType: TIpType type value.

BrowseAndResolve (UnicodeString, Unicodestring, integer, unicodestring, string, TIpType): Boolean  overload

Forcibly browses for a service on the AHostTarget host. If the service is found, this method returns the information in the out parameters.

function BrowseAndResolve(const AHostTarget: UnicodeString; out fullDomainName: Unicodestring; out port: integer; out txtRecord: unicodestring; out addresses: string; aIpType: TIpType): Boolean

Parameters:

  • AHostTarget: Host target
  • fullDomainName: Full domain name
  • port: Port
  • txtRecord: Additional service information like channel, message type etc.
  • addresses: Address
  • aIpType: TIpType type value.

ROFreeNotification    (declared in TROComponent)

Forwards notification messages to all owned RO components.

procedure ROFreeNotification(AComponent: TComponent)

Parameters:

  • AComponent: component

RORemoveFreeNotification    (declared in TROComponent)

Disables destruction notification for specified RO component.

procedure RORemoveFreeNotification(AComponent: TComponent)

Parameters:

  • AComponent: component

Stop

Cancels the service search.

procedure Stop

TriggerFailed  protected override

Executes the OnError event.

procedure TriggerFailed(const ACurrentEngine: TROZeroConfEngine; anException: Exception)

Parameters:

  • ACurrentEngine: Current engine
  • anException: Exception

 

OnError

This event is raised when an error occurs during service browsing.

property OnError: TROZeroConfBrowserError read write
delegate: procedure OnError(Sender: TROZeroConfBrowser; const ACurrentEngine: TROZeroConfEngine; anException: Exception)

OnServiceAdded

Fires whenever a new service is found. The aRecord property will hold a reference to the TROZeroConfService that can be used to receive information about the discovered service.

property OnServiceAdded: TROZeroConfBrowserResultEvent read write
delegate: procedure OnServiceAdded(Sender: TROZeroConfBrowser; aRecord: TROZeroConfService)

OnServiceRemoved

Fires whenever a service is no longer available. The aRecord property will hold a reference to the TROZeroConfService that can be used to receive information about the service.

property OnServiceRemoved: TROZeroConfBrowserResultEvent read write
delegate: procedure OnServiceRemoved(Sender: TROZeroConfBrowser; aRecord: TROZeroConfService)

See Also