mirror of
https://github.com/Karmaz95/Snake_Apple.git
synced 2026-03-30 14:00:16 +02:00
Adding client_server NSConnection example
This commit is contained in:
15
X. NU/custom/mach_ipc/client_server_NSConnection/Makefile
Normal file
15
X. NU/custom/mach_ipc/client_server_NSConnection/Makefile
Normal file
@@ -0,0 +1,15 @@
|
||||
CC = clang
|
||||
CFLAGS = -framework Foundation
|
||||
|
||||
all: client server
|
||||
|
||||
client: client.m
|
||||
$(CC) $(CFLAGS) client.m -o client
|
||||
|
||||
server: server.m
|
||||
$(CC) $(CFLAGS) server.m -o server
|
||||
|
||||
clean:
|
||||
rm -f client server *.o
|
||||
|
||||
.PHONY: all clean
|
||||
17
X. NU/custom/mach_ipc/client_server_NSConnection/client.m
Normal file
17
X. NU/custom/mach_ipc/client_server_NSConnection/client.m
Normal file
@@ -0,0 +1,17 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
@autoreleasepool {
|
||||
if (argc != 2) {
|
||||
NSLog(@"Usage: %s <message>", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
NSConnection *connection = [NSConnection connectionWithRegisteredName:@"com.crimson.message_service" host:nil];
|
||||
id<NSObject> server = [connection rootProxy];
|
||||
|
||||
NSString *message = [NSString stringWithUTF8String:argv[1]];
|
||||
[server handleMessage:message];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
22
X. NU/custom/mach_ipc/client_server_NSConnection/server.m
Normal file
22
X. NU/custom/mach_ipc/client_server_NSConnection/server.m
Normal file
@@ -0,0 +1,22 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@interface MessageServer : NSObject
|
||||
- (void)handleMessage:(NSString *)message;
|
||||
@end
|
||||
|
||||
@implementation MessageServer
|
||||
- (void)handleMessage:(NSString *)message {
|
||||
NSLog(@"Received: %@", message);
|
||||
}
|
||||
@end
|
||||
|
||||
int main() {
|
||||
@autoreleasepool {
|
||||
MessageServer *server = [[MessageServer alloc] init];
|
||||
NSConnection *connection = [NSConnection defaultConnection];
|
||||
[connection setRootObject:server];
|
||||
[connection registerName:@"com.crimson.message_service"];
|
||||
[[NSRunLoop currentRunLoop] run];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user