Connect to local network device knowing only port it runs on.

Hi,
Objective:
iOS 14, iPhone needs to connect to device on local network without knowing its hostname; only port is known.

Do I understand it correctly that the only way to do it is to request com.apple.developer.networking.multicast entitlement and execute:

Code Block
guard let multicast = try? NWMulticastGroup(for:
[ .hostPort(host: "224.0.0.251", port: 5353) ])
else { fatalError(...) }
let group = NWConnectionGroup(from: multicast, using: .udp)
group.setReceiveHandler(maximumMessageSize: 16384, rejectOversizedMessages: true) { (message, content, isComplete) in
print("Received message from \(String(describing: message.remoteEndpoint))")
}


Then from
Code Block
message.remoteEndpoint
I can infer hostname (with matching port, of course) to which I need initiate
Code Block
NWConnection
?

Thanks

Code source

Answered by Systems Engineer in 670781022

Do I understand it correctly that the only way to do it is to request com.apple.developer.networking.multicast entitlement and execute:

Communicating over a NWMulticastGroup is one way to connect to a device on a local network without knowing the hostname. Some use SSDP for this type of communication. If you know the service that is being used on the network or the local name of the machine you need to connect to, you can also use Bonjour.


Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Accepted Answer

Do I understand it correctly that the only way to do it is to request com.apple.developer.networking.multicast entitlement and execute:

Communicating over a NWMulticastGroup is one way to connect to a device on a local network without knowing the hostname. Some use SSDP for this type of communication. If you know the service that is being used on the network or the local name of the machine you need to connect to, you can also use Bonjour.


Matt Eaton
DTS Engineering, CoreOS
meaton3@apple.com
Thanks @meaton! Since I cannot conform service to SSDP, do not know service and machine local name then my only option is to use NWMulticastGroup.
Connect to local network device knowing only port it runs on.
 
 
Q