I am wondering how to do Inter-App Communication on iOS in iOS 7. It occurred to me that if I was the foreground app I could bind to sockets and act like a server, and if I was the background app (and had a background entitlement like audio) then I can connect to servers. So it seemed to me like it would be possible to do Inter-App Communication by agreeing on a port between 2 apps and simply switching which app binds to a port based on whether it is in the foreground or not.
Problem is, I can never seem to connect to localhost from the background, for example I have this code on a loop:
truct addrinfo *server_address;
int ret = getaddrinfo("localhost", "1666", NULL, &server_address);
int connection_id = connect(self.socketHandle, server_address->ai_addr, server_address->ai_addrlen);
And connection_id is always -1. I am unsure why I cannot connect given the bind process does not throw any errors.