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);
    var
    I : integer;
    begin
    // discover all managers
    Button1.Enabled := false;
    Label1.Caption := '0';
    ListBox1.Items.Clear();
    Label2.Caption := '0';
    TotalProfiles := 0;
    ListBox2.Items.Clear();
    for I := TetheringManager1.PairedManagers.Count - 1 downto 0 do
    TetheringManager1.UnPairManager(TetheringManager1.PairedManagers[I]);
    // Tethering Port Range: 2020 to 2040
    // Manager discovery default timeout is 1500 msec
    TetheringManager1.DiscoverManagers(DiscoveryTimeoutSpinEdit.Value);
    end;


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);
    begin
    Password := '1234';
    end;


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);
    var
    I: Integer;
    begin
    // 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
    ListBox1.Items.Add(RemoteManagers.List[I].ManagerName
    + ' - '
    + RemoteManagers.List[I].ConnectionString
    );
    TetheringManager1.PairManager(RemoteManagers[I]);
    end;
    Button1.Enabled := true;
    end;

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


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 http://cc.embarcadero.com/item/29849. Have fun adding app tethering to your VCL and FMX Delphi and C++ XE6 applications.
About
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

  • Guest
    Mark Monday, 28 April 2014

    When't the BlueTooth version going to be available?

  • Guest
    David Intersimone Monday, 28 April 2014

    Mark - R&D is working on blue tooth support for the future. When? When it is ready. The architecture underpinnings are there. Note the use of the "profiles" in the network version for this release :)

  • Guest
    Torbins Tuesday, 29 April 2014

    "discovery works by broadcasting a message across TCP ports 2020 to 2040"
    ? Probably broadcasting is done via UDP, and the rest of communication via TCP.

  • Guest
    David Intersimone Wednesday, 30 April 2014

    Torbins - you are right - we use UDP for the broadcast on the subnet and then TCP/IP for the communications. I will update my blog post to make this even clearer than just using the "broadcast" word and assuming everyone knows this means UDP :) I should also learn how to spell "milliseconds" - I fixed those typos as well :(

  • Guest

    [...] created a blog post back in April, "Finding your Tethered Apps", that contains additional information about App Tethering and shows you how to find tethered apps [...]

  • Guest

    [...] David I blog – “Finding your Tethered Apps” [...]

  • Guest
    Jack Baird Thursday, 31 July 2014

    Hi David,

    Is the TTetheringManager/TTetheringAppProfile communication encrypted in any way? if not is that kind of feature on the roadmap for these components?

    Regards,

    Jack

  • Guest

    [...] also blogged earlier this year showing you how to find all of the tethered applications, "Finding your Tethered Apps" on your subnet. You can find that blog post at [...]

  • Please login first in order for you to submit comments
  • Page :
  • 1