Unable to send files between 2 devices using Network Framework

I'm having trouble using network framework to transfer a collection of 1 minute video files between a recording device and a repository master device. All devices are on the same wifi. But the problem is that the distance between devices somehow is player a role in the transfer. When I have strong wifi signal on both devices, but if the devices are further than 100 feet apart, the transfer won't happen. Conversely, if both devices have very weak wifi signal (e.g. 1 bar), but are next to each other, the transfer happens without a hitch. It's as if the devices are doing something more akin to wifi direct than transfer for a LAN, which is what I really want. I'm assuming someone familiar with the framework can advise how to entirely avoid using any peer to peer wifi direct type of transfer, and force the system to transfer over the WLAN. That way all I need to do is make sure all devices have a decent wifi signal (e.g. are on the network with a decent connection), and regardless of how far they are physically from each other, the files will transfer without a hitch. Hope someone can clear this up for me.

  1. We are using the mDNS approach.
 func startBrowsing() {
     guard browser == nil else { return }

     let params = NWParameters()
     params.includePeerToPeer = true
     params.requiredInterfaceType = .wifi
     let browser = NWBrowser(for: .bonjour(type: bonjourService, domain: nil), using: params)
     self.browser = browser

     browser.browseResultsChangedHandler = { 
         [weak self] results, changes in
         guard let self = self else { return }
         self.delegate?.peerBrowser(self, didUpdateResults: Array(results))
     }

     browser.stateUpdateHandler = { [weak self] newState in
         guard let self = self else { return }
         os_log("[browser] %@", newState.debugDescription)

         switch newState {
         case .cancelled:
             break
         case .failed:
             os_log("[browser] restarting")
             self.browser?.cancel()
             self.startBrowsing()
         case .ready:
             break
         case .setup:
             break
         @unknown default:
             break
         }
     }

     browser.start(queue: .main)
 }
  1. There are no such errors. I can see the standard communication is still working and because of that the sender(iPhone) will continue to send the files to iPad (receiver) with out fail but the receiver couldn’t able to receive it.

  2. Devices do not fail to connect and are able to transfer data as well as there is no timeouts or disconnections happening.

  3. The code used to send data from one peer to another.

   func sendMessage(type: UInt32, content: Data) {
        guard connection?.state == .ready else {
            return
        }
    
        let framerMessage = NWProtocolFramer.Message(messageType: type)
        let context = NWConnection.ContentContext(identifier: "Message", metadata: [framerMessage])
    
        connection?.send(content: content, contentContext: context, isComplete: true, completion: .idempotent)
    }

If the devices are on the same infrastructure Wi-Fi then you don’t need peer-to-peer Wi-Fi enabled. So, just as a test, what do you see if you comment out all the places where you set includePeerToPeer?

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Unable to send files between 2 devices using Network Framework
 
 
Q