How to connect multiple peers to iPhone apps via Wi-Fi?

I have an idea for an ios application (iPhone) that needs to connect to multiple peers. I base my code on the WiTab example (SampleCode-developer.apple.com).

When my application started each peer, creating a separate Socket (CFSocket) and publishing through the NSNetService Class. In particular, the NSNetServiceBrowser class finds available peers. And display their name in the TableView. When I select a row in the table view, the corresponding resolved host-address is allowed, the connection and the receive-receive data are established.

But my intention is that I want to select multiple rows in a tableView (multiple peers). and the selected peer address is allowed. For this, I saved the selected peer information in NSMutableArray. When I click (touch) the submit button, I want to resolve the selected device address and send data to the selected peers. For this, I made this code

for(int k=0;k<[selectedService count];k++) { self.currentResolve = [self.selectedService objectAtIndex:k]; self.currentResolve = [self.selectedSer objectAtIndex:k]; [self.currentResolve setDelegate:self]; [self.currentResolve resolveWithTimeout:60]; } 

But it will only allow one device (self.selectedService objectAtIndex: 0). Since I can solve several peers. Address / connection establishment for several devices. therefore my doubts: -

  • Is it possible to connect more than one device via WiFi?
  • If so, what is the maximum number of devices that can be connected in one template?
  • What type of CFSocket is useful for multiple connections (TCP / UDP)?
  • Do I need to create multiple CFSockets in each peer?
  • If so, how? Do they have any documents?
  • Is an established session required?
  • How to resolve the address for a mutple device?
+4
source share
2 answers

Its quite difficult to change the Apple.Developer Witap application, because you need to keep all allowed addresses, change all methods and process the lot.

I think this tutorial will reach your goal.

The application is called " Chatty ". Its source code is here.

Download the App --> Open --> Click-on Chatti project tab --> Build Settings --> Change the base SDK to iOS6

it is issued under the MIT license , which means that you are free to modify and reuse

In this lesson, they are going to learn the chat application for the iPhone. It allows you to host your chat room and advertise it on your local network. (in this case, your application acts as a "chat server"), or you can find and join chats posted by other people on your network (acting as a "chat" client). Both the announcement and the opening of chats are implemented using the Apples Bonjour protocol , the same as the Witap Application

Now I answer your questions

Is it possible to connect more than one device via WiFi?

Yes, you can

If so, what is the maximum number of devices that can be connected in the same template?

I think you can combine with any number of devices

What type of CFSocket is useful for multiple connections (TCP / UDP)?

My suggestion is TCP

The remaining answers to your questions can be easily understood from the Chatty sample application :)

Note The server and clients must be on the same WiFi network.

+8
source

Depending on the nature of your application, you can use the GamKit Framework, and it will provide even more features than your request. The following are safety precautions.

  • Game center

6.1 Applications displaying any player identifier to end users or third parties will be rejected 6.2 Applications using player identifiers for any use other than those approved by the Game Center will be rejected 6.3 Developers who are trying to change the search, tracing, matching, associating, extracting, collecting or otherwise using identifiers, a pseudonym, or other information obtained from the Game Center will be deleted from the iOS 6.4 developer program Game center information such as Leaderboard ratings can only be used in Applications approved for use in Game Center 6.5. Applications that use the Game Center service to send unsolicited messages or for phishing or spam will be rejected. 6.6 Applications that overuse network bandwidth or bandwidth Game Center will be rejected 6.7 Applications that transmit viruses, files, computer code or programs that could harm or interfere with the normal operation of the Game Center service will be rejected.

0
source

Source: https://habr.com/ru/post/1390615/


All Articles