Anonymous user
Distributed programming: Difference between revisions
m
→{{header|Objective-C}}: modernize
m (removed omit REXX. -- ~~~~) |
m (→{{header|Objective-C}}: modernize) |
||
Line 649:
int main (void)
{
@autoreleasepool {
NSSocketPort *port = (NSSocketPort *)[NSSocketPort port];
// initWithTCPPort: 1234 and other methods are not supported yet
// by GNUstep
NSConnection *connect = [NSConnection
connectionWithReceivePort: port
sendPort: port]; // or sendPort: nil
[connect setRootObject: action];
/* "vend" the object ActionObject as DistributedAction; on GNUstep
the Name Server that allows the resolution of the registered name
is bound to port 538 */
if (![connect registerName:@"DistributedAction"
withNameServer: [NSSocketPortNameServer sharedInstance] ]
{
NSLog(@"can't register the server DistributedAction");
exit(EXIT_FAILURE);
}
NSLog(@"waiting for messages...");
[[NSRunLoop currentRunLoop] run];
▲ }
return 0;
}</lang>
Line 692 ⟶ 687:
int main(void)
{
@autoreleasepool {
id <ActionObjectProtocol> action;▼
[NSConnection
rootProxyForConnectionWithRegisteredName: @"DistributedAction" ▼
host: @"localhost"
usingNameServer: [NSSocketPortNameServer sharedInstance] ];▼
if (action == nil)▼
NSLog(@"can't connect to the server");▼
▲ rootProxyForConnectionWithRegisteredName: @"DistributedAction"
}▼
▲ usingNameServer: [NSSocketPortNameServer sharedInstance] ];
▲ if (action == nil)
{▼
▲ NSLog(@"can't connect to the server");
▲ }
NSArray *args = [[NSProcessInfo processInfo] arguments];
if ([args count] == 1)
{
NSLog(@"specify a message");
exit(EXIT_FAILURE);
}
NSString *msg =
// "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);
return 0;
}</lang>
|