After spending the whole weekend building a fancy (read: hacked together) TCP socket server in my application I think I need to change the fundamental way I integrated it into my application.

I decided to put all of the logic for the application into the server and have the client communicate over TCP, even if the client was the process that actually _started_ the server. The reason being there would be no difference between a local client and a remote one, just the IP address it would connect to.

I decided to run the server as an XCP service, because it’s a nice easy way to make little sub-processes in macOS. All of that actually worked quite nicely, except for one fundamental part of the application: Apple Events, which have to be called on the main thread. Unfortunately in an XPC service the main thread is blocked by the service listener, meaning the Apple Events can’t run.

The solution is going to be moving logic (and Apple Events) back into the main app, still running the socket server XPC service, but forwarding messages to the server which remote clients can receive. Luckily most of the code will still work, I just need to change how it all fits together.


A resounding "OMG it fucking works!?" from the refactor.

Sign in to participate in the conversation
Mastodon is one server in the network