简体   繁体   中英

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.

Turning on the includesPeerToPeer property of NSNetService enables service discovery over peer to peer Bluetooth and Wi-Fi, which means that it is advertising over both bluetooth and WiFi.

The reason for performance issues may be related to communications happening over bluetooth, which is a relatively slow connection in comparison to WiFi.

I don't know the answer to (2), I can only surmise that this is the reason why you're seeing the performance problem is because communications are happening over bluetooth. I don't know of any way to force the connection over WiFi only - I've read the docs several times and can't see a way of changing that.

I've seen a lot of recommendations for disabling bluetooth to get better performance for local games, though.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM