Understanding “includesPeerToPeer” property of NSNetservice

I am developing a 3D Wi-Fi multiplayer game for iPhone and iPad without using any game engine. I have taken reference of the “WiTap” sample for device connectivity for local Wi-Fi multiplayer game (Link to the sample code:WiTap).


I found that there is a performance drop in the game when I set “includesPeerToPeer” property to YES, but I found that the game performance is better when I set “includesPeerToPeer” property to NO. Also, the game performance drop is more when the device bluetooth is turned ON.

I am setting this property to YES to allow faster discovery of devices (to avoid bug described here:Bug).I am testing my game on iPhone 5 (running on iOS 8.4) and iPad 3rd generation (running on iOS 7.1).


I have two questions:

  1. How includesPeerToPeer property of NSNetservice can affect my game performance? What is the difference in the connection establishment between the two devices when I set the property to YES or NO (and device bluetooth is turned OFF)?
  2. When devices bluetooth is kept ON, why there is a performance drop? Are these devices connected via bluetooth whenever bluetooth is available? If yes, how can I restrict my devices to communicate only over Wi-Fi?

I’d appreciate any suggestions on this issue. Thank you in advance.

There are two issues here:

  • Performance can drop when you enable Bluetooth for two reasons:

    • It’s possible for the connection to be made over Bluetooth, which is slower than Wi-Fi, obviously.

    • Bluetooth and Wi-Fi share the same antenna, so enabling Bluetooth can impact on Wi-Fi performance even if you’re connected over Wi-Fi.

  • Turning on

    includesPeerToPeer
    also enables peer-to-peer Wi-Fi. That can impact on performance because of the way in which peer-to-peer Wi-Fi is implemented on our current hardware.

There’s not much you can do about this at the NSNetService layer. With the lower-level Bonjour API,

<dns_sd.h>
, it’s possible to control exactly which peer-to-peer links are used, but for NSNetService it’s either all or nothing.

Regardless of what you do with the above information, it’s important that you stop any ongoing Bonjour operations once you no longer need them. For example, if your game is connected and running, it’s critical that you stop any ongoing Bonjour browse and resolve operations, lest they adversely affect your game’s networking (you may also want to stop registrations as well, but that’s less critical for performance than the other two).

Share and Enjoy

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

let myEmail = "eskimo" + "1" + "@apple.com"
  • Thank you for the feedback. I have checked my code and I found that all the Bonjour operations stop when the game is connected and running.
  • Can you help me in understanding the differences between peer to peer Wi-Fi connection and normal Wi-Fi connection between the devices implemented using NSNetService?
  • Is it good practise to ask the user to turn OFF Bluetooth before starting Wi-Fi multiplayer game?

Can you help me in understanding the differences between peer to peer Wi-Fi connection and normal Wi-Fi connection between the devices implemented using NSNetService?

Peer-to-peer Wi-Fi works even if the devices are not on the same infrastructure Wi-Fi network; they just have to be in range of each other.

Without

includesPeerToPeer
, NSNetService will only work if both devices are associated to the same Wi-Fi network within the same multicast domain (that is, device B can see multicasts sent by device A).

Is it good practise to ask the user to turn OFF Bluetooth before starting Wi-Fi multiplayer game?

I can’t really answer that.

Share and Enjoy

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

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

Thank you for the quick and helpful reponse. It was easy to understand the includesPeerToPeer property from the information provided by you.

Understanding “includesPeerToPeer” property of NSNetservice
 
 
Q