Distributed programming: Difference between revisions

m
m (removed omit REXX. -- ~~~~)
Line 649:
int main (void)
{
@autoreleasepool {
NSAutoreleasePool *pool;
ActionObject *action;
NSConnection *connect;
NSSocketPort *port;
pool ActionObject *action = [[NSAutoreleasePoolActionObject alloc] init];
action = [[ActionObject alloc] init];
 
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] ] == NO)
{
NSLog(@"can't register the server DistributedAction");
exit(EXIT_FAILURE);
}
NSLog(@"waiting for messages...");
 
[[NSRunLoop currentRunLoop] run];
 
}
[pool release];
return 0;
}</lang>
Line 692 ⟶ 687:
int main(void)
{
@autoreleasepool {
NSAutoreleasePool *pool;
NSArray *args;
id <ActionObjectProtocol> action;
NSString *msg, *backmsg;
 
id <ActionObjectProtocol> action; = (id <ActionObjectProtocol>)
pool = [[NSAutoreleasePool alloc] init];
[NSConnection
rootProxyForConnectionWithRegisteredName: @"DistributedAction"
host: @"localhost"
usingNameServer: [NSSocketPortNameServer sharedInstance] ];
 
if (action == nil)
action = (id <ActionObjectProtocol>)
[NSConnection{
NSLog(@"can't connect to the server");
rootProxyForConnectionWithRegisteredName: @"DistributedAction"
host: @"localhost"exit(EXIT_FAILURE);
}
usingNameServer: [NSSocketPortNameServer sharedInstance] ];
 
if (action == nil)
{
NSLog(@"can't connect to the server");
exit(EXIT_FAILURE);
}
NSArray *args = [[NSProcessInfo processInfo] arguments];
 
if ([args count] == 1)
{
NSLog(@"specify a message");
exit(EXIT_FAILURE);
}
NSString *msg = [args objectAtIndex: [1];
 
// "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);
 
{}
[pool release];
return 0;
}</lang>
Anonymous user