Since Apple Multipeer framework does not really work without crashes, I implemented my own multipeer with the Network.framework. like
let tcpOptions = NWProtocolTCP.Options.createDefault()
let parameters = NWParameters(tls: NWProtocolTLS.Options(), tcp: tcpOptions)
parameters.setDefaultSettings()
let browser = NWBrowser(
for: .bonjour(
type: config.bonjourServiceType,
domain: nil
),
using: parameters
)
and
extension NWParameters {
func setDefaultSettings() {
self.includePeerToPeer = true
self.requiredInterfaceType = .wifi
self.preferNoProxies = true
}
}
extension NWProtocolTCP.Options {
static func createDefault() -> NWProtocolTCP.Options {
let tcpOptions = NWProtocolTCP.Options()
tcpOptions.enableKeepalive = true
tcpOptions.keepaliveIdle = 10 // 10 seconds keepalive interval
tcpOptions.noDelay = true // Disable Nagle's algorithm for low latency
return tcpOptions
}
}
it works well up to approx. 30 meter outside with free view. What's the max range for the peer to peer via bonjour? And is there a way to get longer distance than 30 meter?