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 BonjourDiscovery sample shipped with the Remoting SDK to see service discovery in action.

Location


 

constructor Create  override

Standard component constructor

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

Executes the OnError event.

function BrowseAndResolve(aTimeout: Integer; const aHostTarget: UnicodeString; out aFullDomainName: UnicodeString; out aPort: Integer; out aTXTRecord: UnicodeString; out aAddresses: string; aIpType: TIpType): Boolean

Parameters:

  • aTimeout: Timeout (in seconds)
  • aHostTarget: Host target
  • aFullDomainName: Full domain name
  • aPort: Port
  • aTXTRecord: Additional service information like channel, message type etc.
  • aAddresses: Address
  • aIpType: TIpType type value.

BrowseAndResolve (UnicodeString, UnicodeString, Integer, UnicodeString, string, TIpType): Boolean  overload

Executes the OnError event.

function BrowseAndResolve(const aHostTarget: UnicodeString; out aFullDomainName: UnicodeString; out aPort: Integer; out aTXTRecord: UnicodeString; out aAddresses: string; aIpType: TIpType): Boolean

Parameters:

  • aHostTarget: Host target
  • aFullDomainName: Full domain name
  • aPort: Port
  • aTXTRecord: Additional service information like channel, message type etc.
  • aAddresses: 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

Notification  protected override    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure Notification(aComponent: TComponent; Operation: TOperation)

Parameters:

  • aComponent: component
  • Operation: operation

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 components.

procedure ROFreeNotification(aComponent: TComponent)

Parameters:

  • aComponent: component

RORemoveFreeNotification    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure RORemoveFreeNotification(aComponent: TComponent)

Parameters:

  • aComponent: component

SendRemoveNotification  protected    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure SendRemoveNotification(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

Standard component constructor

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

Executes the OnError event.

function BrowseAndResolve(aTimeout: Integer; const aHostTarget: UnicodeString; out aFullDomainName: UnicodeString; out aPort: Integer; out aTXTRecord: UnicodeString; out aAddresses: string; aIpType: TIpType): Boolean

Parameters:

  • aTimeout: Timeout (in seconds)
  • aHostTarget: Host target
  • aFullDomainName: Full domain name
  • aPort: Port
  • aTXTRecord: Additional service information like channel, message type etc.
  • aAddresses: Address
  • aIpType: TIpType type value.

BrowseAndResolve (UnicodeString, UnicodeString, Integer, UnicodeString, string, TIpType): Boolean  overload

Executes the OnError event.

function BrowseAndResolve(const aHostTarget: UnicodeString; out aFullDomainName: UnicodeString; out aPort: Integer; out aTXTRecord: UnicodeString; out aAddresses: string; aIpType: TIpType): Boolean

Parameters:

  • aHostTarget: Host target
  • aFullDomainName: Full domain name
  • aPort: Port
  • aTXTRecord: Additional service information like channel, message type etc.
  • aAddresses: Address
  • aIpType: TIpType type value.

Notification  protected override    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure Notification(aComponent: TComponent; Operation: TOperation)

Parameters:

  • aComponent: component
  • Operation: operation

ROFreeNotification    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure ROFreeNotification(aComponent: TComponent)

Parameters:

  • aComponent: component

RORemoveFreeNotification    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure RORemoveFreeNotification(aComponent: TComponent)

Parameters:

  • aComponent: component

SendRemoveNotification  protected    (declared in TROComponent)

Forwards notification messages to all owned components.

procedure SendRemoveNotification(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)