I hope to use Worker(s) as lightweight server(s) in my desktop app, offloading the server function to other cores. When I run my app in the IDE it works well, but the built app does not.
The confirmation that a WebSocket is Listening is that MacOS presents the user with an alert “Do you want the application ‘myApp.debug.app’ to accept incoming connections?” and when running in the IDE the user sees this message, but not with the built app. The Firewall Options list has an entry for my app to allow incoming connections.
The problem seems to have to do with the worker running as a console application, it can no longer initialize its websocket correctly. I am not shown the “Do you want the application…to accept incoming connections?” alert, and client browsers cannot connect.
I have some experience using Workers and I understand that in this application the worker needs to be persistent. In the worker, the WebSocket and its active connections are properties of the worker and the first time through the JobRun() event I do WebSocket.Listen, and (in the IDE) client connections do persist until the worker is stopped.
Don’t use workers for this. They’re not meant to be persistent. Just make your own console app and put it in the helpers folder of the bundle. Keep in mind that each ServerSocket app that you spin up will need to listen on a separate port.
Also, probably most importantly, make sure you sign the console app.
Thanks Greg. I’d use an IPC socket to communicate with it.
How would I launch and quit the console app?
I’ve discovered it’s actually due to the fact that the built app has not included the worker. …strange.
There is no Helpers/Workers folder in the app’s Contents. Nor is there a _CodeSignature item in the bundle, even though there is a Sign build step.
So to wrap this up: For some reason the Worker was not being compiled and added to the built bundle. I created a separate test project (Desktop Application) and added the Worker to that, and it compiled successfully.
So then I put the compiled Worker into my original applications built bundle (i.e. Helpers/Workers/MyWorker) and it works!
My original application is a large project and very old code base. The IDE would compile another dummy Worker object that I added to the project for troubleshooting, but it refused to compile the worker I needed. Very strange, but happy ending.