Can you specify port for NWListener.Service without creating an NWListener on that port

I'm running a webserver for a specific service on port 8900 I'm using telegraph to run the webserver, so that opens and claims the port.

I also want to advertise the service on bonjour - ideally with the correct port.

This is trivial with NetService - but that's deprecated, so I should probably move to the Network framework.

I can advertise without specifying a port

listener = try NWListener(service: service, using: .tcp)

but, then my service broadcasts addresses with port:61443

I can advertise using listener = try NWListener(using: .tcp, on: <myport>)

however, that fails in my use case because (unsurprisingly) the Listener isn't able to get the port (my server already has it)

Is this just a gap in the new API, or am I missing something?

Can you specify port for NWListener.Service without creating an NWListener on that port

No.

Is this just a gap in the new API … ?

No. Network framework is focused on networking and this sort of thing is outside of its scope. For advanced Bonjour use cases like this one, reach for the low-level DNS-SD API.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Can you specify port for NWListener.Service without creating an NWListener on that port
 
 
Q