diff --git a/X. NU/custom/mach_ipc/client_server_CFMessagePort/Makefile b/X. NU/custom/mach_ipc/client_server_CFMessagePort/Makefile new file mode 100644 index 0000000..7e7852b --- /dev/null +++ b/X. NU/custom/mach_ipc/client_server_CFMessagePort/Makefile @@ -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 \ No newline at end of file diff --git a/X. NU/custom/mach_ipc/client_server_CFMessagePort/client.m b/X. NU/custom/mach_ipc/client_server_CFMessagePort/client.m new file mode 100644 index 0000000..0f3a5fe --- /dev/null +++ b/X. NU/custom/mach_ipc/client_server_CFMessagePort/client.m @@ -0,0 +1,16 @@ +#import + +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; +} \ No newline at end of file diff --git a/X. NU/custom/mach_ipc/client_server_CFMessagePort/server.m b/X. NU/custom/mach_ipc/client_server_CFMessagePort/server.m new file mode 100644 index 0000000..1dfa808 --- /dev/null +++ b/X. NU/custom/mach_ipc/client_server_CFMessagePort/server.m @@ -0,0 +1,18 @@ +// server.m +// clang -framework Foundation server.m -o server +#import + +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; +} \ No newline at end of file