Did setting includePeerToPeer solve your issues? I have the same issues you describe above, but I am setting includePeerToPeer=true.
The only real difference is that I'm using TLS with a key. This works with simulated or real devices on the same broadcast domain, e.g. same VLAN, same SSID, or same multicast domain. I can see the advertisement on a different SSID or VLAN, but I cannot connect. I also have a function where you can specify an IP Address. Since I force advertising on a specific port and can start a connection with Bonjour locating the service, I am at a loss why I can't connect across the broadcast domain. Here is how I'm setting my NWParameters:
extension NWParameters {
convenience init( authenticatingWithKey key: Data ) {
let tlsOptions = NWProtocolTLS.Options()
let symmetricKey = SymmetricKey( data: key )
let code = HMAC<SHA256>.authenticationCode( for: Data( "AppleConnect".utf8 ), using: symmetricKey ).withUnsafeBytes( DispatchData.init )
sec_protocol_options_add_pre_shared_key( tlsOptions.securityProtocolOptions, code as dispatch_data_t, Data( "WindowProjectionTest".utf8 ).withUnsafeBytes( DispatchData.init ) as dispatch_data_t )
sec_protocol_options_append_tls_ciphersuite( tlsOptions.securityProtocolOptions, tls_ciphersuite_t( rawValue: numericCast( TLS_PSK_WITH_AES_128_GCM_SHA256 ) )! )
// TLS PSK requires TLSv1.2 on Apple platforms - See https://developer.apple.com/forums/thread/688508.
sec_protocol_options_set_max_tls_protocol_version( tlsOptions.securityProtocolOptions, .TLSv12 )
sec_protocol_options_set_min_tls_protocol_version( tlsOptions.securityProtocolOptions, .TLSv12 ) // Requires Second Attempt
self.init( tls: tlsOptions )
defaultProtocolStack.applicationProtocols.insert( NWProtocolFramer.Options( definition: .init( implementation: ConnectProtocol.self ) ), at: 0 )
// Set Connection Configuration
acceptLocalOnly = false
allowLocalEndpointReuse = true
includePeerToPeer = true
prohibitedInterfaceTypes = [ NWInterface.InterfaceType.loopback ]
// Force IPv4
if let isOption = defaultProtocolStack.internetProtocol as? NWProtocolIP.Options {
isOption.version = .v4
}
}
}
Topic:
App & System Services
SubTopic:
Networking
Tags: