如何通过 WiFi 连接 iPhone 应用程序上的多个对等点? [英] How to Connect multiple peers on the iPhone Application over WiFi?

查看:99
本文介绍了如何通过 WiFi 连接 iPhone 应用程序上的多个对等点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ios(iPhone) 应用程序的想法,该应用程序需要连接到多个对等点.我的代码基于 WiTab (SampleCode-developer.apple.com) 示例.

I have an idea for an ios(iPhone) application to which requires connecting to several peers. I am basing my code on the WiTab (SampleCode-developer.apple.com) example.

当我的应用程序启动每个对等点时,创建单独的 Socket(CFSocket) 并通过 NSNetService 类发布.特别是 NSNetServiceBrowser 类找到可用的对等点.并在TableView中显示他们的名字.当我在表视图中选择行时,对应的对端地址解析,连接建立,发送接收数据成功.

When my application started each peer creating separate Socket(CFSocket) and publishing through NSNetService Class.In particular instance NSNetServiceBrowser class find available peers. And display their name in TableView.When i select row in the table view the corresponding peer address resolved, a connection established and sending-receiving data was successfully.

但我的意图是,我想在 tableView 中选择多行(多个对等).并解析选定的对等地址.为此,我将选定的对等点信息存储到 NSMutableArray.当我单击(触摸)发送按钮时,我想解析选定的设备地址并将数据发送到选定的对等方.为此,我做了这个代码

But my intention is ,I want to select multiple row in the tableView (multiple peer). and resolved selected peers address. For that I stored selected peers information to the NSMutableArray. When i click(touch) send button , I want to resolve Selected Device address and send data to selected peers. For that i did 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];           
  }

但它只会解析一个设备(self.selectedService objectAtIndex:0).那么我如何解析多个对等地址/如何为多个设备建立连接.所以我的怀疑是:-

But it will resolved only one device(self.selectedService objectAtIndex:0).So how can i resolved multiple peers Address/ how to established connection for multiple device. so my doubts are:-

  1. 是否可以通过 WiFi 同时连接多个设备?
  2. 如果是,可以以相同模式连接的最大设备数量是多少?
  3. 哪种类型的 CFSocket 对多连接(TCP/UDP)有用?
  4. 是否需要在每个 peer 中创建多个 CFSocket?
  5. 如果是,如何?他们有任何可用的文件吗?
  6. 是否需要建立会话?
  7. 如何解析多个设备的地址?

推荐答案

Apple.Developer Witap 应用程序很难修改,因为您需要保存所有已解析的地址,必须修改所有方法和处理很多.

Its pretty hard to modify the Apple.Developer Witap application because you need to hold all the resolved adresses , have to modify all the methods and handle lot.

我认为本教程将实现您的目标.

I think this tutorial will achieve your goal.

该应用名为Chatty".其源代码位于此处

The app is called "Chatty." Its source code is located here

下载应用程序 -->打开 -->单击 Chatti 项目选项卡 -->构建设置 -->将基础 SDK 更改为 iOS6

它是在 MIT 许可下发布的,这意味着您可以自由修改和重复使用

it is being released under the MIT license, which means that you are free to modify and reuse it at will

在本教程中,他们将探索一个简单的 iPhone 聊天应用程序.它允许您托管自己的聊天室并在您的本地 Wi-Fi 网络上做广告(在这种情况下,您的应用充当聊天服务器")或查找并加入其他人托管的聊天室在您的网络上(充当聊天客户端").聊天室的公告和发现均使用 Apple 的 Bonjour 协议实现,与 Witap 应用程序相同

In this tutorial, They are going to explore a simple chat application for the iPhone. It allows you to host your own chat room and advertise it on your local Wi-Fi network (in which case your app acts as a chat "server") or find and join chat rooms hosted by other people on your network (acting as a chat "client"). Both announcement and discovery of chat rooms are implemented using Apple’s Bonjour protocol same as Witap Application

现在我来回答你的每一个问题

Now I'm answering your each questions

是否可以通过 WiFi 同时连接多个设备?

是的,你可以

如果是,可以连接的最大设备数量是多少?相同的模式?

我认为您可以与任意数量的设备配对

I think you can pair with any number of devices

哪种类型的 CFSocket 对多连接(TCP/UDP)有用?

我的建议是 TCP

您的问题的其余答案可以从示例 Chatty 应用程序中轻松理解:)

The remaining answers for your questions can be easily understand from the sample Chatty App :)

注意:服务器和客户端需要在同一个 WiFi 网络上

Note: The server and clients need to be on the same WiFi network

这篇关于如何通过 WiFi 连接 iPhone 应用程序上的多个对等点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆