RosettaCodeData/Task/Distributed-programming/Objective-C/distributed-programming-5.m

39 lines
942 B
Mathematica
Raw Permalink Normal View History

2013-04-10 22:43:41 -07:00
#import <Foundation/Foundation.h>
#import "ActionObjectProtocol.h"
int main(void)
{
2014-04-02 16:56:35 +00:00
@autoreleasepool {
2013-04-10 22:43:41 -07:00
2014-04-02 16:56:35 +00:00
id <ActionObjectProtocol> action = (id <ActionObjectProtocol>)
[NSConnection
rootProxyForConnectionWithRegisteredName: @"DistributedAction"
host: @"localhost"
usingNameServer: [NSSocketPortNameServer sharedInstance] ];
2013-04-10 22:43:41 -07:00
2014-04-02 16:56:35 +00:00
if (action == nil)
{
NSLog(@"can't connect to the server");
exit(EXIT_FAILURE);
}
NSArray *args = [[NSProcessInfo processInfo] arguments];
2013-04-10 22:43:41 -07:00
2014-04-02 16:56:35 +00:00
if ([args count] == 1)
{
NSLog(@"specify a message");
exit(EXIT_FAILURE);
}
2013-04-10 22:43:41 -07:00
2014-04-02 16:56:35 +00:00
NSString *msg = args[1];
2013-04-10 22:43:41 -07:00
2014-04-02 16:56:35 +00:00
// "send" (call the selector "sendMessage:" of the (remote) object
// action) the first argument's text as msg, store the message "sent
// back" and then show it in the log
NSString *backmsg = [action sendMessage: msg];
NSLog("%@", backmsg);
}
2013-04-10 22:43:41 -07:00
return 0;
}