Hi all,
I am writing a program which has a Client- Server architecture, where in multiple independent process connects to my server and get serviced. I was reading about XPC which helps me achieve this, but the description says XPC API's helps us to create light weight helper tools in your application (XPC services) which work on behalf of your application.
I tried a small POC where in, I used below XPC API's
Server
xpc_connection_t listener = xpc_connection_create_mach_service("com.companyName.mcspMacXPCServerTest", dispatch_get_main_queue(),XPC_CONNECTION_MACH_SERVICE_LISTENER);
xpc_connection_set_event_handler(listener, ^(xpc_object_t event)
{
// New connections arrive here.
std::cout << "Event Handler on listener is called" << std::endl; XpcClientTest_event_handler((xpc_connection_t)event);
});
I registered the server with launchd and connect it from a Client that needs to be serviced.
Client
xpc_connection_t conn = xpc_connection_create_mach_service("com.mcafee.mcspMacXPCServerTest", NULL, XPC_CONNECTION_MACH_SERVICE_PRIVILEGED);
xpc_connection_set_event_handler(conn, ^(xpc_object_t event) {
// Always set an event handler. More on this later.
// std::cout << "Received an message event..." << std::endl;
});
xpc_connection_send_message_with_reply(conn, message, dispatch_get_main_queue(), ^(xpc_object_t event) {
const char* response = xpc_dictionary_get_string(event, "reply");
printReplyFromServer(response);
});
I was able to successfully Send and Receive messages between the Client-Server. Even created multiple instances of Client and tried to connect to Server and was successful.
My Question is Can we use XPC API's independently of XPC Services not as a helper tool ? Can I use XPC in this manner where in multiple independent process connects to my server and get serviced ?
Thanks in advance for all the help/Suggestions
~Arjun