MegaDemo sample (Cocoa)

This is the combined sample demonstrating various features of RO SDK, supported by RemObjects SDK for Xcode:

  • ZeroConf service discovery
  • TCP and HTTP channels
  • Different message types
  • URL schemas
  • simple values and structures transfer

Server Requirements

The MegaDemo Client sample requires the MegaDemo Server either for Delphi or for .NET. Look into the MegaDemo (Delphi) or the MegaDemo (.NET) sample for it.

Getting Started

Build and launch the MegaDemo sample server for the platform you like. Activate HTTP, TCP or both servers in the server application. The sample allows you to test HTTP or TCP client channel class together with Binary or SOAP message classes. Data compression can be enabled or disabled for Binary messaging.
There are 3 alternative ways to specify the connection settings the client will use:

  • Using ROZeroConf (Bonjour) service discovery. You can select one of the servers discovered from the combo box and click the button next to it to apply settings. Values in other controls in the Channel Setup group will change accordingly.
  • Using separate controls to set up every parameter. Select channel type, target host name or IP address, port. Look how Target URL field changes to reflect your settings.
  • Specifying target URL. Enter target URL into the Target URL field according to the rules. If the URL is correct the Channel Setup group controls will update their values upon Target URL field exit.

Try to perform different operations with the server. Select a desired tab page, enter required data into the fields and click the Run Test Once button. You can view the operations log in the drawer log window, click the Show Log (or Hide Log) button to toggle drawer visibility. The operations that can be performed on the server are:

  • Sum two integer values.
  • Send a structure (Person type) to the server and back.
  • Send an array of different element type (including array of structures) to the server and back.
  • Send a binary stream to the server and back.
  • Call a parameterless remote function (get server time).
  • Handle an exception raised on the server, including exceptions of custom type.

Examine the code

The AppController class is responsible for the sample operations. There are several methods named -(BOOL)perform<something>, e.g. -(BOOL)performSum. Examine them to see how the sample operations are performed.
Pay attention on how channel and message instances are created. The code part responsible for it is:

- (IBAction)runTestOnce:(id)sender 
{
    NSDate *startTime;
    NSDate *endTime;
    NSTimeInterval timeDiff;
    
    megaDemoLibrary = [[MegaDemoService_Proxy alloc] initWithURL:[self currentTragetURL]];
    if ([[megaDemoLibrary __message] isKindOfClass:[ROBinMessage class]])
        [(ROBinMessage *)[megaDemoLibrary __message] setUseCompression:[chkCompression state] == NSOnState];
    if ([[megaDemoLibrary __message] isKindOfClass:[ROSoapMessage class]])
        [(ROSoapMessage *)[megaDemoLibrary __message] setSoapMode:ROSoapModeRPCEncoding];
...

As you can see, channel and message instances are created implicitly by the initWithURL: call. All information required to create proper instances is encoded inside the target URL. The only thing left to do is to make fine-tuning of the instances created, in this case we need some additional setup depending on the message used.