mirror of
https://github.com/Karmaz95/Snake_Apple.git
synced 2026-09-29 00:01:44 +02:00
Adding client_server CFMessagePort example
This commit is contained in:
1 parent
b735706891
commit
043c2714f1
3 files changed
+49
No files matched your search
@@ -0,0 +1,15 @@
|
|||||||
|
CC = clang
|
||||||
|
FRAMEWORK = -framework Foundation
|
||||||
|
|
||||||
|
all: client server
|
||||||
|
|
||||||
|
client: client.m
|
||||||
|
$(CC) $(FRAMEWORK) client.m -o client
|
||||||
|
|
||||||
|
server: server.m
|
||||||
|
$(CC) $(FRAMEWORK) server.m -o server
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -f client server *.o
|
||||||
|
|
||||||
|
.PHONY: all clean
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]) {
|
||||||
|
@autoreleasepool {
|
||||||
|
if (argc != 2) return 1;
|
||||||
|
|
||||||
|
CFMessagePortRef port = CFMessagePortCreateRemote(NULL, CFSTR("com.crimson.message_service"));
|
||||||
|
if (port) {
|
||||||
|
NSString *msg = [NSString stringWithUTF8String:argv[1]];
|
||||||
|
NSData *data = [msg dataUsingEncoding:NSUTF8StringEncoding];
|
||||||
|
CFMessagePortSendRequest(port, 0, (__bridge CFDataRef)data, 1, 1, NULL, NULL);
|
||||||
|
CFRelease(port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// server.m
|
||||||
|
// clang -framework Foundation server.m -o server
|
||||||
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
|
static CFDataRef callback(CFMessagePortRef port, SInt32 msgid, CFDataRef data, void *info) {
|
||||||
|
NSLog(@"Received: %@", [[NSString alloc] initWithData:(__bridge NSData *)data encoding:NSUTF8StringEncoding]);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
@autoreleasepool {
|
||||||
|
CFMessagePortRef port = CFMessagePortCreateLocal(NULL, CFSTR("com.crimson.message_service"), callback, NULL, NULL);
|
||||||
|
CFRunLoopSourceRef source = CFMessagePortCreateRunLoopSource(NULL, port, 0);
|
||||||
|
CFRunLoopAddSource(CFRunLoopGetCurrent(), source, kCFRunLoopCommonModes);
|
||||||
|
[[NSRunLoop currentRunLoop] run];
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in new issue
Block a user