iPhone - 通过互联网的点对点连接
我正在构建一个使用异步套接字与 Web 服务器连接的应用程序。 为了发送大量数据,我想使用异步套接字将两部 iPhone 连接到点对点连接。我对 GCDAsyncSocket 比对 iOS SDK 套接字 API 更熟悉。
我已经做了类似的事情,但只有在本地网络中,我才会使用 NSNetService 来发布存在并从 p2p 连接获取所需的地址。
您能给我一些关于如何使用 p2p 套接字连接通过互联网连接两部 iPhone 的提示吗?
I am building an app that uses a async socket connection with a web server.
For sending large amounts of data I would like to connect two iPhones into a Peer to Peer connection using an async socket. I am more familiar with GCDAsyncSocket than to the iOS SDK socket API.
I have done something similar, but only within a local network were I would user NSNetService to publish a presence and get the addresses needed from the p2p connection.
Can you give me a hint on how to connect two iPhone over the internet using a p2p socket connection?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我对 NSNetService 不太了解,但它似乎只适用于本地网络。如果您想建立从一台 iphone 到另一台 iphone 的 p2p 连接,您的路由中总会遇到多个 NAT(网络地址转换器)的问题。如何找到到对端的地址和路由?以及如何通过所有的防火墙和 NAT?
我正在开发一个需要处理相同问题的应用程序,并且我已经回答了一个类似的问题,在此之前我将在此引用:
现在,如果您发现此解决方案有帮助并尝试实现它,请告诉我您是否成功获取服务器端服务器-客户端连接的公共 IP 和端口。您还可以回答我在 stackoverflow 上提出的问题。
I do not know much about NSNetService but it seems that it only works in a local network. If you want to establish a p2p connection from an iphone to another you will always have the problem of several NATs (Network address translators) in your route. How to find the address and route to the peer? And how to get trough all the firewalls and NATs?
I am working on an app that needs to deal with the same problem and I have answered a similar question before which I will cite here:
Now if you find this solution helpful and you try to implement it, please tell me if you are successful in getting the public ip and port of the server-client connection on the server side. You can also answer my question about this on stackoverflow.
请具体说明,您可以使用 GCDAsyncSocket 连接 2 部手机,您可以使用来自 Github 的示例代码。
Please be specific, u may use GCDAsyncSocket to connect 2 phones, u may use sample code from Github.