Finding your Tethered Apps

Posted by on in Blogs
RAD Studio XE6, Delphi XE6 and C++Builder XE6 include support for tethering your VCL and FMX apps together. This blog post shows you how to display all of the tethered apps that you can find on your subnet. App Tethering includes two components: TTetheringManager and TTetheringAppProfile. For this article I've built a Delphi VCL application that uses these two components to discover the other tethered apps that are running on the my subnet. The example tether application demo I used is the PhotoWall sample that ships with the release (you can find it in the C:\Users\Public\Documents\Embarcadero\Studio\14.0\Samples\Object Pascal\RTL\Tethering\PhotoWall folder)

Here is the main form for my application showing a TButton, TSpinEdit, two TListbox and some TLabels.  The TSpinEdit is used to set the timeout for the TetheringManager.DiscoverManagers optional second parameter.

The app tethering discovery works by using UDP to broadcast a discovery message across ports 2020-2040. The default timeout for the manager discovery period is 1500 milliseconds. The default timeout for the profiles discovery is 5000 milliseconds. Make sure that you open up the app tethering ports in your firewall if they are not already open. If your network is busy, you might want to set the discovery timeout longer than 1500 milliseconds (I normally use 3000 milliseconds at work and the default at home).

The TButton onClick event handler code is very straightforward:

    procedure TForm1.Button1Click(Sender: TObject);
    I : integer;
    // discover all managers
    Button1.Enabled := false;
    Label1.Caption := '0';
    Label2.Caption := '0';
    TotalProfiles := 0;
    for I := TetheringManager1.PairedManagers.Count - 1 downto 0 do
    // Tethering Port Range: 2020 to 2040
    // Manager discovery default timeout is 1500 msec

In my Find Tethered Apps application I provide three event handlers for my TetheringManager: OnEndManagersDiscovery, OnEndProfilesDiscovery and OnRequestManagerPassword.

If your Tethered Apps have a password set in their TetheringManager property, you'll need to provide a n OnRequestManagerPassword event handler to get any responses from the remote tether apps.

    procedure TForm1.TetheringManager1RequestManagerPassword(const Sender: TObject;
    const RemoteIdentifier: string; var Password: string);
    Password := '1234';

After the call to DiscoverManagers, the app tethering technology listens for replies from other TetherManagers and TetherProfiles. When the timeout period completes, the OnEndManagersDiscovery and OnEndProfilesDiscovery events are executed. The event handlers code displays the TetherManagers with their IPaddress and Port and the TetherProfiles with their GUID.

    procedure TForm1.TetheringManager1EndManagersDiscovery(const Sender: TObject;
    const RemoteManagers: TTetheringManagerInfoList);
    I: Integer;
    // end of managers discovery - list those found
    // use RemoteManagers parameter to build ListBox1
    Label1.Caption := IntToStr(RemoteManagers.Count);
    for I := 0 to RemoteManagers.Count-1 do begin
    + ' - '
    + RemoteManagers.List[I].ConnectionString
    Button1.Enabled := true;

    procedure TForm1.TetheringManager1EndProfilesDiscovery(const Sender: TObject;
    const RemoteProfiles: TTetheringProfileInfoList);
    I: Integer;
    // Tethering Port Range: 2020 to 2040
    // Profile discovery default timeout is 5000 msec
    // use RemoteProfiles parameter to build ListBox1
    Label2.Caption := IntToStr(TotalProfiles);
    for I := 0 to RemoteProfiles.Count-1 do begin
    + ' - '
    + RemoteProfiles.List[I].ProfileIdentifier
    Button1.Enabled := true;

For my test run, I started the VCL and FMX PhotoWall desktop apps and then started the mobile PhotoWall apps on my iPhone and Android phone. The resulting display shows the four tethered apps in my FindTetheredApps demo along with pictures that I took on my two mobile devices and sent to the two desktop apps.

The source code to my Delphi Find Tethered Apps project is available in CodeCentral at Have fun adding app tethering to your VCL and FMX Delphi and C++ XE6 applications.
Gold User, Rank: 1, Points: 2466
David Intersimone (known to many as David I.) is a passionate and innovative software industry veteran-often referred to as a developer icon-who extols and educates the world on Embarcadero developer tools. He shares his visions as an active member of the industry speaking circuit and is tapped as an expert source by the media. He is a long-standing champion of architects, developers and database professionals and works to ensure that their needs are folded into Embarcadero's strategic product plans. David holds a bachelor's degree in computer science from California Polytechnic State University at San Luis Obispo, California.
Comments are not available for public users. Please login first to view / add comments.