DataSnap.Failover - DataSnap HTTP Tunneling Sample

From Appmethod Code Examples
Jump to: navigation, search

This sample illustrates the DataSnap HTTP Tunneling. Failover is the capability of automatically switching to a redundant server.

Location

You can find the Failover - DataSnap HTTP Tunneling sample project at:

Description

The Failover - DataSnap HTTP Tunneling application is used to:

  • Demonstrate the use of DataSnap HTTP Tunneling.
  • Demonstrate the DataSnap controls.
  • Demonstrate the creation of a simple DataSnap server.
  • Demonstrate how to use DataExplorer and stored procedures.

How to Use the Sample

  1. Navigate to Start | Programs | Appmethod 1.14 | Samples, go to Object Pascal\DataSnap\Failover, and open the FailoverDemo.groupproj project group.
  2. Build Failover.dproj.
  3. Run the application by selecting the Run > Run menu from within the IDE, or by pressing F9.
  4. Build MyServer.dproj.
  5. Run the application by selecting the Run > Run menu from within the IDE, or by pressing F9.
  6. Select the 211 port and start the server by clicking the Start/Stop button.
  7. Run another instance of MyServer.dproj and this time define the port 213. Start the server.
  8. Go back to the IDE and point to the Data Explorer window.
  9. Create a new DataSnap connection using the Data Explorer.
  10. Modify the DataSnap connection by right-clicking it and selecting Modify Connection. Set the Protocol to http, the Host to localhost, and the Port to 8020. Leave Path as blank. Set the User Name to admin and the Password to admin.
  11. Now go to the Procedures root in the DataSnap connection tree and look for the TServerMethod1.EchoString server method. Right-click it and select View Parameters. For the Value parameter, set its Value field to the Object Pascal string, for instance.
  12. Click the execute button. A window will appear containing the message Object Pascal 211.
  13. Now stop the DataSnap server connected to port 211.
  14. Re-execute the stored procedure. A window will appear containing the message Object Pascal 213.
  15. Switch to the Failover running program and observe the Log.

Files

File Contains

DSUtilityUnit

DataSnap utility class and methods.

Failover

The Failover project itself.

FormServer

The main form that constitutes the user interface for the DataSnap Server.

HTPServerTest

The main form that constitutes the user interface for the Failover Sample application.

MyServer

The DataSnap Server project itself.

ServerContainerUnit1

The DataSnap Server container.

ServerMethodsUnit1

Contains the DataSnap Server Methods declarations and implementations.

Classes

  • TDSUtilityMethods is part of the Failover project and implements the DataSnap utility methods like JSONPing, FailOn, EchoStr, and so on.
  • TServerMethods1 is part of the MyServer project and implements the DataSnap server methods such as EchoString.

Implementation

The Failover - DataSnap HTTP Tunneling Sample application is structured in two parts.

The DataSnap Server

  • Provides a simple DataSnap Server that has the EchoString server method implemented.
  • The server permits the selection of the communications port and allows the user to start or stop the server using a button.
  • The DataSnap Server uses the TDSServer component, the TDSServerClass component, and a TDSServerClass to actually implement the server.

The Failover Application

  • Demonstrates the use of DataSnap HTTP Tunneling.
  • Has a user interface based on a memo that holds a log of everything that happens behind. Also, it shows the number of tunnel sessions and has the ability to enable or disable the failover.

Uses

See Also