@meaton hi and thanks for the help. I checked the endPoint and it's definitely set (below)
I do not believe there is an option to add data to TLS options that does not work inside the context of TLS. How is the extension from NWParameters expected to work in this case for NWListener and NWConnection? Based on what @eskimo said about each peer having its own a unique ID, this seemed like the only way to add it. That is the only reason I took that approach. Since you said that the way I'm doing isn't possible, then I wonder what he meant by that. I'll go back to that thread and ask him there or email him for further explanation.
As per the multiple call problem that I'm having, yes you are correct:
you are getting a browsing client reaching your Bonjour service and the listener is accepting the new connection Using a device as the browser and simulator as the listener, I just added a print statement to listener.newConnectionHandler and when the connection came in, this is the print out:
endpoint: fe80::149d:ff95:503f:9d9%en4.59013
endpoint: fe80::149d:ff95:503f:9d9%en4.59014
endpoint: fe80::149d:ff95:503f:9d9%en4.59015
endpoint: fe80::837:3ac4:fb1f:492e%en1.63936
Connection preparing // stops here
Listener:
listener.newConnectionHandler = { [weak self](newConnection) in
		self?.delegate?.createNewIncoming(newConnection) // called in the below vc that conforms to the delegate
}
vc:
var	connectionIncoming: ConnectionIncoming?
func createNewIncoming(_ connection: NWConnection) {
		print("endpoint: ", connection.endPoint)
		connectionIncoming = ConnectionIncoming(connection:connection, delegate: self)
}
NWConnection class named ConnectionIncoming:
class ConnectionIncoming {
private var connection: NWConnection?
		// ...
		connection.stateUpdateHandler = { [weak self](nwConnectionState) in
				 switch nwConnectionState {			
				 case .preparing: 	
							 print("Connection preparing") // still stuck here				
				 // ...		
				}
		}
}
Here is the basic browser code if it makes any difference:
protocol PeerBrowserDelegate: class {
func createConnection(from endPoint: NWEndpoint)
}
class PeerBrowser {
		weak var delegate: PeerBrowserDelegate?
		fileprivate var browser: NWBrowser?
		init() {
let parameters = NWParameters()
parameters.includePeerToPeer = true
browser = NWBrowser(for: .bonjour(type: "_myApp._tcp", domain: "local"), using: parameters)
startBrowsing()
}
		fileprivate func startBrowsing() {
guard let browser = browser else { return }
browser.stateUpdateHandler = { [weak self](newState) in
switch newState {
case .setup: print("Browser - setup")
case .ready: print("Browser - ready")
case .cancelled: print("Browser - Cancelled")
case .failed(let error): /* restart code ... */
default:break
}
}
browser.browseResultsChangedHandler = { [weak self](results, changes) in
for result in results {
let endPoint = result.endpoint
self?.delegate?.createConnection(from: endPoint) // will create a NWConnection from endPoint
break
}
}
browser.start(queue: .main)
}
}