How to create a Remoting SDK Client (Cocoa)
This topic will explain the basic steps to get started writing native Mac OS X desktop clients using Remoting SDK for Cocoa.
Remoting SDK for Cocoa (RO/Cocoa for short) does not ship with project templates for client applications because, frankly, in most cases you will want to add Remoting SDK client functionality to an existing project or to one you are starting based on any of the project templates or samples provided by Apple.
There are three basic steps involved in turning your project into a RO client:
- linking in the Remoting SDK library,
- generating and adding Interface code for your server RODL,
- instantiating and using instances of the Remoting SDK classes.
Linking in the Remoting SDK library
Remoting SDK for Cocoa ships as a so-called Framework
that works similarly to frameworks such as Cocoa itself that ship with Mac OS X. Frameworks bundle all the information needed to work with a library, including binary files and header sources.
The Linking Custom Frameworks from your Xcode Projects article explains in detail how to add references to frameworks (RemObjectsSDK.framework or others) and is a recommended read to fully understand the concept. For quickly getting started, it will suffice to locate the appropriate RemObjectsSDK.framework bundle in your Remoting SDK installation (two pre-built combinations are provided, for Release and Debug mode) and drag it into your project.
Generating Interface Code for Your Server RODL
There are two ways to generate Objective-C interface code to talk to your specific services from the Mac. One option is to install the ROSBOSX.dll plugin dll (shipped in the /Tools folder) into Service Builder on your Windows development machine (or VM) and use that to generate Objective-C .m
and .h
files from your RODL from within Service Builder. Alternatively, you can open your RODL file with the rodl2objc Mac application that ships with RO/OSX (once again in the /Tools folder), and generate code from there.
Once you have a .m
and .h
file for your RODL, simply add the files to your Xcode project as normal source files (by dragging them into the folder tree, or by right-clicking the project node and choosing Add -> Existing Files...
).
The Generating Interface Code from Your RODL topic covers this process in more detail.
Calling Your Services
Once everything is set up, you're ready to make calls to your service or services. Like in all editions of RO, there are three major class types involved here: a message, a client channel and a proxy that was generated in your Intf file and represents your service.
So you will instantiate copies of these three classes and make your call, such as:
// create message and channel
NSURL *targetURL = [NSURL URLWithString:@"http://myServer:8099/bin"];
ROBinMessage *message = [[[ROBinMessage alloc] init] autorelease];
ROHTTPClientChannel *channel = [[[ROHTTPClientChannel alloc] initWithTargetURL:targetURL] autorelease];
// create your proxy (here from the ROiPhonePhoto sample)
MegaDemoService_Proxy *p = [[[MegaDemoService_Proxy alloc] initWithMessage:message
channel:channel] autorelease];
// and make your call
int result = [p Sum:3:5]; // returns 8
And that's it, a call will be made to your server's Sum::
method.