如何通过 WiFi 连接 iPhone 应用程序上的多个对等点?
我有一个 ios(iPhone) 应用程序的想法,它需要连接到多个对等点。我的代码基于 WiTab (SampleCode-developer.apple.com) 示例。
当我的应用程序启动每个对等点时,创建单独的套接字(CFSocket)并通过 NSNetService 类发布。特别是 NSNetServiceBrowser 类实例查找可用的对等点。并在 TableView 中显示它们的名称。当我在表视图中选择行时,解析了相应的对等地址,连接建立并成功发送接收数据。
但我的意图是,我想在 tableView 中选择多行(多个对等)。并解析选定的对等点地址。为此,我将选定的对等点信息存储到 NSMutableArray 中。当我单击(触摸)发送按钮时,我想解析选定的设备地址并将数据发送到选定的对等点。为此,我做了这段代码
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)。那么我如何解析多个对等点地址/如何为多个设备建立连接。 所以我的疑问是:-
- 是否可以通过 WiFi 同时连接多个设备?
- 如果可以,同一模式下最多可以连接多少台设备?
- 哪种类型的 CFSocket 对于多连接(TCP/UDP)有用?
- 是否需要在每个peer中创建多个CFSocket?
- 如果是,怎么办?他们有什么可用的文件吗?
- 是否需要建立会话?
- 如何解析多个设备的地址?
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.
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.
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];
}
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:-
- Is it possible to connect more than one device simultaneously over WiFi?
- If yes,What is the maximum number of device that can be connected in same pattern?
- Which type of CFSocket is useful for multiple Connection(TCP/UDP)?
- Is it required to create multiple CFSocket in each peer?
- If Yes,how? their is any documents available ?
- Is it required to established session?
- How to resolve address for mutple device?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
修改Apple.Developer Witap应用程序非常困难,因为您需要保存所有已解析的地址,必须修改所有方法和句柄。
我认为本教程将实现您的目标。
该应用程序名为“Chatty”。其源代码位于此处
下载应用程序 -->打开-->单击 Chatti 项目选项卡 -->构建设置 -->将基础 SDK 更改为 iOS6
它是在 MIT 许可证下发布的,这意味着您可以随意自由修改和重用它
在本教程中,他们将探索一个简单的 iPhone 聊天应用程序。它允许您托管自己的聊天室,并在您的本地 Wi-Fi 网络上宣传它(在这种情况下,您的应用充当聊天“服务器”),或者查找并加入其他人托管的聊天室在您的网络上(充当聊天“客户端”)。聊天室的公告和发现都是使用Apple的与Witap应用程序相同的Bonjour协议来实现的,
现在我正在回答您的每个问题
您问题的其余答案可以从示例 Chatty 应用程序中很容易理解:)
注意:服务器和客户端需要位于同一 WiFi 网络上
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.
The app is called “Chatty.” Its source code is located here
Download the App --> Open --> Click-on Chatti project tab --> Build Settings --> Change the base SDK to iOS6
it is being released under the MIT license, which means that you are free to modify and reuse it at will
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
The remaining answers for your questions can be easily understand from the sample Chatty App :)
Note: The server and clients need to be on the same WiFi network
根据您的应用程序的性质,您可以使用 GamKit Framework,它将提供比您要求的更多的功能。以下是需要采取的预防措施。
6.1
向最终用户或任何第三方显示任何玩家 ID 的应用程序将被拒绝
6.2
将玩家 ID 用于游戏中心条款批准之外的任何用途的应用程序将被拒绝
6.3
尝试反向查找、追踪、关联、关联、挖掘、收获或以其他方式利用通过游戏中心获得的玩家 ID、别名或其他信息的开发者将从 iOS 开发者计划中删除
6.4
游戏中心信息(例如排行榜分数)只能在经批准与游戏中心一起使用的应用程序中使用
6.5
使用 Game Center 服务发送未经请求的消息或出于网络钓鱼或垃圾邮件目的的应用程序将被拒绝
6.6
过度使用游戏中心网络容量或带宽的应用程序将被拒绝
6.7
传输病毒、文件、计算机代码或可能损害或破坏 Game Center 服务正常运行的程序的应用程序将被拒绝
Depending on the nature of your app you could use GamKit Framework and it will provide even more features than your asking for. Here are the precautions to take.
6.1
Apps that display any Player ID to end users or any third party will be rejected
6.2
Apps that use Player IDs for any use other than as approved by the Game Center terms will be rejected
6.3
Developers that attempt to reverse lookup, trace, relate, associate, mine, harvest, or otherwise exploit Player IDs, alias, or other information obtained through the Game Center will be removed from the iOS Developer Program
6.4
Game Center information, such as Leaderboard scores, may only be used in Apps approved for use with the Game Center
6.5
Apps that use Game Center service to send unsolicited messages, or for the purpose of phishing or spamming will be rejected
6.6
Apps that excessively use the network capacity or bandwidth of the Game Center will be rejected
6.7
Apps that transmit viruses, files, computer code, or programs that may harm or disrupt the normal operation of the Game Center service will be rejected