saagarjha / AppleConnect

Peer-to-peer bidirectional connection based on Network.framework
GNU Lesser General Public License v3.0
109 stars 4 forks source link

Is there a concept to stop advertising the server once a connection has been made? #1

Open pennstump opened 5 hours ago

pennstump commented 5 hours ago

If not, how might you accomplish that? I have tried stopping the NWListener, but that did not stop a Server from showing up to other clients.

saagarjha commented 3 hours ago

To advertise you call Connection.advertise(forServiceType:name:key:), which hands you back an AsyncStream of clients that want to connect. If you stop iterating over the results (for example by breaking out the loop you're consuming it with) then the cleanup for that should stop advertising–at least, in theory. Let me know if that's what you're looking for.