Peer-to-Peer UDP

We're trying to establish a peer-to-peer UDP connection for video streaming, but are running into some issues. I can get it to work using the iOS 12 Network framework (which works very well) but need to support older versions of iOS as well.


- As far as I can diagnose, it seems the problem is that a UDP connection doesn't keep the WiFi link active (i.e. `awdl0`). Does that diagnosis make sense and would the be any way to prevent this from happening?

- Should using `MultipeerConnectivity` using `sendData(… with: .unreliable)` achieve comparable characteristics and performance to direct P2P UDP? As I understand MC uses UDP internally (though left as implementation detail) and just mimicks TCP over UDP for its ordered/reliable sending methods, is that correct?


Any help would be greatly appreciated!

Accepted Reply

As far as I can diagnose, it seems the problem is that a UDP connection doesn't keep the WiFi link active (i.e.

awdl0
). Does that diagnosis make sense

It’s certainly a reasonable theory. On the TCP front, getting peer-to-peer Wi-Fi working (prior to the Network framework) requires that use

NSNetService
for your listener (with
NSNetServiceListenForConnections
) because that has some secret sauce to activate the peer-to-peer Wi-Fi interface.

and would the be any way to prevent this from happening?

One option would be to first set up a TCP connection using

NSNetService
and then, once that’s running, use BSD Sockets for your main traffic. This isn’t necessarily a bad idea anyway, because it’s often helpful to have a TCP connection lying around for command and control purposes.

Should using

MultipeerConnectivity
using
sendData(… with: .unreliable)
achieve comparable characteristics and performance to direct P2P UDP?

I’d expect so.

As I understand MC uses UDP internally

Correct.

and just mimicks TCP over UDP for its ordered/reliable sending methods, is that correct?

I wouldn’t say it that way. Rather, I’d say that it implements its own ordered/reliable protocol on top of UDP. One does not simply mimic TCP (-:

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

As far as I can diagnose, it seems the problem is that a UDP connection doesn't keep the WiFi link active (i.e.

awdl0
). Does that diagnosis make sense

It’s certainly a reasonable theory. On the TCP front, getting peer-to-peer Wi-Fi working (prior to the Network framework) requires that use

NSNetService
for your listener (with
NSNetServiceListenForConnections
) because that has some secret sauce to activate the peer-to-peer Wi-Fi interface.

and would the be any way to prevent this from happening?

One option would be to first set up a TCP connection using

NSNetService
and then, once that’s running, use BSD Sockets for your main traffic. This isn’t necessarily a bad idea anyway, because it’s often helpful to have a TCP connection lying around for command and control purposes.

Should using

MultipeerConnectivity
using
sendData(… with: .unreliable)
achieve comparable characteristics and performance to direct P2P UDP?

I’d expect so.

As I understand MC uses UDP internally

Correct.

and just mimicks TCP over UDP for its ordered/reliable sending methods, is that correct?

I wouldn’t say it that way. Rather, I’d say that it implements its own ordered/reliable protocol on top of UDP. One does not simply mimic TCP (-:

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

You marked my response as correct and I’m curious what that means. Did you end up using Multipeer? Or my TCP as a command-and-control channel approach?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Missed them, but better late than never! We're now primarily using Network.framework, with a TCP command-and-control channel and UDP for the video frames. For older devices we're using multipeer with `.unreliable`. Definitely the Network.framework version works better though and the improved control it provides is great.