简体   繁体   English

如何在iPhone应用程序中进行点对点通信?

[英]How to do peer-to-peer communication in an iPhone app?

I'm trying to write a simple chat application for the iPhone (as an experiment). 我正在尝试为iPhone编写一个简单的聊天应用程序(作为实验)。 Is there a simple way for two devices to discover each others' IP addresses, and given the addresses is there a simple API or protocol that would let me send text messages back and forth? 是否有一种简单的方法让两个设备发现彼此的IP地址,并且考虑到地址是否有一个简单的API或协议可以让我来回发送文本消息?

I've investigated SIP (specifically Sofia and eXosip), but these tools exist as C libraries and are beyond my current ability to port them to the iPhone. 我已经研究过SIP(特别是Sofia和eXosip),但是这些工具作为C库存在,并且超出了我目前将它们移植到iPhone的能力。

Update: I'm trying to connect two devices over the Internet (ie not over Bluetooth or a local wireless network, which is what GameKit does). 更新:我正在尝试通过互联网连接两台设备(即不通过蓝牙或本地无线网络,这是GameKit所做的)。

You're going to need a server that provides the match making service. 您将需要一个提供匹配服务的服务器。 Game Center makes this pretty easy, but your users will have to have Game Center accounts. 游戏中心使这很容易,但您的用户必须拥有游戏中心帐户。

Alternatively, you can set up an XMPP (formerly Jabber, it's what powers Google Chat) server (I've never done this, but there are several available) and use the XMPP Framework for Cocoa . 或者,您可以设置一个XMPP(以前称为Jabber,它是Google Chat的功能)服务器(我从未这样做,但有几个可用)并使用XMPP Framework for Cocoa There are instructions for using it in iPhone apps here . 有在iPhone应用程序使用它说明在这里

I'm sure there are other chat servers and client source also available. 我确信还有其他聊天服务器和客户端来源。 IRC and Mobile Colloquy come to mind. 我想到了IRC和Mobile Colloquy

Finally, you could write your own server using your favorite server language / framework. 最后,您可以使用自己喜欢的服务器语言/框架编写自己的服务器。 This isn't too hard (I've done it myself), but it's far from what I'd call simple, and I wouldn't use it for a production system. 这不是太难(我自己做过),但它远非我所谓的简单,我不会将它用于生产系统。

There is support for exactly this kind of ad-hoc peer-to-peer networking in GameKit. 在GameKit中确实支持这种特殊的对等网络。 Have a look at the second half of the GameKit documentation for details: 有关详细信息,请查看GameKit文档的后半部分:

http://developer.apple.com/library/ios/#documentation/... HTTP://developer.apple.com/library/ios/#documentation / ...

NSNetService是一个不错的选择。

Take a look at WebRTC Datachannels . 看看WebRTC Datachannels WebRTC is a newer option with native iOS support a standard that is still being finalized, but it is more flexible should the iOS app need to communicate with browser or even android peers WebRTC是一个较新的选项, 原生iOS支持标准仍在最终确定,但如果iOS应用程序需要与浏览器或甚至Android同行进行通信,它会更灵活

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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