RTL.DesktopCast Sample

From RAD Studio Code Examples
Jump to: navigation, search

DesktopCast is a sample application with a client-server architecture where a client application can connect to a server application and receive a screenshot taken by the server application once or every 5 seconds using app tethering. The server application is a VCL application, and the client application is available both as a VCL application and as a FireMonkey application.

Location

You can find the DesktopCast project at:

Description

This group of projects provides two client projects (VCL and FireMonkey) and a server project. The projects are designed so that at a given time you have one of the client projects and the server project running and reachable using app tethering.

In the server application you have the following buttons:

  • TakeFullScreenShot takes a screenshot and shows the screenshot.
  • StartLiveCast starts taking screenshots each 5 seconds and showing them.
  • StopLiveCast stops taking screenshots.

In the client application you have the following buttons:

  • Connect establishes a connection to the running server application.
When the connection finishes, you can see text at the top of the application, over the control buttons. If the connection failed, the message says "You are not connected". If the connection is successful, the message says "Working with: - TTetheringAppProfile1".
  • TakeFullScreenShot or TakeShot executes the server action to take a screenshot remotely.
  • StartLiveCast or Start Cast executes the server action to start taking screenshots every 5 seconds remotely.
  • StopLiveCast or StopCast executes the server action to stop taking screenshots every 5 seconds remotely.

When the server application takes a screenshot, the server application shows the screenshot and shares the screenshot with the client application, that also shows the server screenshot.

The window title of the VCL client application shows also information about the received screenshot (size and date).

DesktopCast.png

How to Use the Sample

  1. Navigate to the location given above and open DesktopCast.groupproj.
  2. Double click the server application entry, VCLTetherDesktop, in the Project Manager to select the server application.
  3. Select Run > Run to run the server application.
  4. Double click one of the client application entries, FMXClientTetherDesktop or VCLTetherClient, in the Project Manager to select a client application.
  5. Select Run > Run to run the selected client application.

Files

Each application in the project group contains a single source file that contains the class for the main form of the application.

Classes

Each application defines a single class that implements the main form of the application.

Implementation

Server Application

  • ActionManager1 defines the following actions (associated with the application buttons):
    • actFullShot executes actFullShotExecute, which updates the screenshot in Image1 using Shot and saves the screenshot to the value of the shared local resource.
    • actStartCast executes actStartCastExecute, which enables tmCast.
    • actStopCast executes actStopCastExecute, which disables tmCast.
  • DesktopTetherManager.Password is "Desktop".
  • TTetheringAppProfile1:
  • There are two methods to take screenshots:
    • ScreenShot takes a screenshot and saves it into the specified TBitmap using BitBlt.
    • Shot takes a screenshot using ScreenShot and shows the screenshot on Image1.
  • The class contains the following members for timing:
    • tmCast is disabled by default. When enabled, this timer runs the tmCastTimer procedure each 5 seconds.
    • tmCastTimer executes the actFullShot action.

FireMonkey Client Application

  • CheckRemoteProfiles updates Label1 with information about the connected remote profiles, if any.
  • CommandManager.OnRequestManagerPassword is handled by CommandManagerRequestManagerPassword, which provides the password of the remote server application: "Desktop".
  • CommandApp:
    • Actions contains three local actions with Mirror as Kind and the same names as the actions shared by the server application. These actions are associated with the actions in ActionList1.
    • The Group is "TetherDesktop".
    • The Manager is CommandManager.
    • Resources contains a single resource with Mirror as Kind and the same name as the resource shared by the server application.
  • ActionList1 defines the same actions as the server application, with the same name, but no implementation as the actions just trigger their remote twins. These actions are associated with their corresponding buttons.
  • tmCheckConnection is disabled by default. When enabled, this timer runs the CheckRemoteProfiles procedure each 2 seconds.
  • Button2 (Connect) when clicked:
    1. Calls CommandManager.AutoConnect.
    2. Enables tmCheckConnection.

VCL Client Application

  • CheckRemoteProfiles updates Label1 with information about the connected remote profiles, if any.
  • DesktopTetherManager:
    • OnEndAutoConnect is handled by DesktopTetherManagerEndAutoConnect, which calls CheckRemoteProfiles.
    • OnRequestManagerPassword is handled by DesktopTetherManagerRequestManagerPassword, which provides the password of the remote server application: "Desktop".
  • TTetheringAppProfile1:
    • Actions contains three local actions with Mirror as Kind and the same names as the actions shared by the server application. These actions are associated with the actions in ActionManager1.
    • The Group is "TetherDesktop".
    • The Manager is DesktopTetherManager.
    • Resources contains a single resource with Mirror as Kind and the same name as the resource shared by the server application.
  • ActionManager1 defines the same actions as the server application, with the same name, but no implementation as the actions just trigger their remote twins. These actions are associates with their respective buttons.
  • tmCheckConnection is disabled by default. When enabled, this timer runs the CheckRemoteProfiles procedure each 2 seconds.
  • Button4 (Connect) when clicked:
    1. Calls DesktopTetherManager.AutoConnect.
    2. Enables tmCheckConnection.

Uses

See Also