NWListener fails with "Operation not permitted" in UI Testing Bundle

Hello,

I am currently struggling with a strange behaviour in an attempt of creating a NWListener:

Given I use some simple code like:

var listener: NWListener = try NWListener(using: .tcp, on: 12345)
listener.newConnectionHandler = connectionHandler
listener.stateUpdateHandler = stateUpdateHandler
listener.start(queue: .main)
dispatchMain()

(with declared connectionHandler as well as stateUpdateHandler), I successfully can open a listener when running the code in a "Command Line Tool" target. Yet, when I attempt to run it in a "macOS U Testing Bundle", I receive a " nw_listener_socket_inbox_create_socket bind failed [1: Operation not permitted]" error.
The sandbox is not enabled on the project; adding com.apple.security.network.server to the entitlements did not help though.

Does anybody know if this has to do with restrictions of the UI testing bundle / XCUITest or -better- how to solve this?

Best,
Chris

This problem is very specific to Apple platforms, so I’m going to request that you post it over on DevForums, in the Core OS > Networking topic area, and I’ll answer there. That way I can rattle on about networking on Apple platforms without boring the ears off everyone else (-:

Share and Enjoy

Quinn “The Eskimo!” @ DTS @ Apple

1 Like

Thank you very much for this suggestion, see you on the other side ;-)
Edit: NWListener fails with “Operation n… | Apple Developer Forums