langs a-z

This commit is contained in:
Ingy döt Net 2013-04-10 22:43:41 -07:00
parent db842d013d
commit d066446780
11389 changed files with 98361 additions and 1020 deletions

View file

@ -0,0 +1,6 @@
#import <Foundation/Foundation.h>
// our protocol allows "sending" "strings", but we can implement
// everything we could for a "local" object
@protocol ActionObjectProtocol
- (NSString *)sendMessage: (NSString *)msg;
@end

View file

@ -0,0 +1,6 @@
#import <Foundation/Foundation.h>
#import "ActionObjectProtocol.h"
@interface ActionObject : NSObject <ActionObjectProtocol>
// we do not have much for this example!
@end

View file

@ -0,0 +1,10 @@
#import <Foundation/Foundation.h>
#import "ActionObject.h"
@implementation ActionObject
-(NSString *)sendMessage: (NSString *)msg
{
NSLog(@"client sending message %@", msg);
return @"server answers ...";
}
@end

View file

@ -0,0 +1,40 @@
#import <Foundation/Foundation.h>
#import "ActionObject.h"
int main (void)
{
NSAutoreleasePool *pool;
ActionObject *action;
NSConnection *connect;
NSSocketPort *port;
pool = [[NSAutoreleasePool alloc] init];
action = [[ActionObject alloc] init];
port = (NSSocketPort *)[NSSocketPort port];
// initWithTCPPort: 1234 and other methods are not supported yet
// by GNUstep
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;
}

View file

@ -0,0 +1,43 @@
#import <Foundation/Foundation.h>
#import "ActionObjectProtocol.h"
int main(void)
{
NSAutoreleasePool *pool;
NSArray *args;
id <ActionObjectProtocol> action;
NSString *msg, *backmsg;
pool = [[NSAutoreleasePool alloc] init];
action = (id <ActionObjectProtocol>)
[NSConnection
rootProxyForConnectionWithRegisteredName: @"DistributedAction"
host: @"localhost"
usingNameServer: [NSSocketPortNameServer sharedInstance] ];
if (action == nil)
{
NSLog(@"can't connect to the server");
exit(EXIT_FAILURE);
}
args = [[NSProcessInfo processInfo] arguments];
if ([args count] == 1)
{
NSLog(@"specify a message");
exit(EXIT_FAILURE);
}
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
backmsg = [action sendMessage: msg];
NSLog("%@", backmsg);
[pool release];
return 0;
}