简体   繁体   English

iPhone套接字侦听蜂窝数据

[英]iPhone socket listener over cellular data

Is it possible for an iPhone (or any other device over a cellular network) to listen on a socket and wait for other iPhones to connect over AT&T network (P2P)? iPhone(或蜂窝网络上的任何其他设备)是否可以在套接字上侦听并等待其他iPhone通过AT&T网络(P2P)连接? We are able to successfully do this over our local network, but not over the AT&T network. 我们能够通过本地网络成功完成此操作,但不能通过AT&T网络成功完成此操作。

I am not a customer of AT&T, but devices on their 3G network are almost certainly behind some form of Network Address Translation , or "NAT" as it is commonly known. 我不是AT&T的客户,但是3G网络上的设备几乎可以肯定落后于某种形式的网络地址转换 (俗称“ NAT”)。

Given that you want two-way communication between devices that are almost certainly both behind (possibly distinct) NATs, you need some method of traversing the NATs in question. 假设您希望在几乎都位于(可能是不同的)NAT之后的设备之间进行双向通信,则需要某种遍历有问题的NAT的方法。 Enter Session Traversal Utilities for NAT , or "STUN" for short. 输入NAT的会话遍历实用程序 ,或简称为“ STUN”。 Also look into generic network hole-punching techniques. 还要研究通用的网络打孔技术。

There is an Objective-C/Cocoa framework for NAT traversal by the name of TCMPortMapper , under the liberal MIT licence. 在自由MIT许可下,存在一个名称为TCMPortMapper的用于NAT遍历的Objective-C / Cocoa框架。 It provides support for UPnP and NAT-PMP , which may or may not get you all of the way there -- it depends on whether AT&T (or any other telco in question) allow you to request ports. 它提供了对UPnPNAT-PMP的支持 ,这可能会或可能不会完全吸引您-它取决于AT&T(或任何其他有问题的电信公司)是否允许您请求端口。

If the above framework isn't enough, you will have to look into providing a well-known (ie on the wide-open Internet) relay server to mediate connections between the two devices. 如果上述框架还不够,您将不得不考虑提供一个著名的(即在开放式Internet上)中继服务器来调解两个设备之间的连接。 This is the method that is generally employed by services like Skype, Hamachi, Xbox Live and others. 这是Skype,Hamachi,Xbox Live等服务通常采用的方法。 Good luck! 祝好运!

I am not a specialist of the iPhone, but that pretty much depends on the transport layers available on the iPhone. 我不是iPhone的专家,但这在很大程度上取决于iPhone上可用的传输层。 If UDP and TCP are available, then there is a chance. 如果UDP和TCP可用,则有机会。 If iPhone have a public IP address (which I doubt), then this is your lucky day, because the answer is yes (at least in theory). 如果iPhone具有公共IP地址(我对此表示怀疑),那么这就是您的幸运日,因为答案是肯定的(至少在理论上是这样)。

You could easily implement a listener for UDP and implement some boiler plate code to establish remote connection. 您可以轻松实现UDP的侦听器并实现一些样板代码以建立远程连接。 But, you'll quickly notice that you'll have to solve more complex issues such as finding peer's public IP address (ie, discovering peers). 但是,您很快就会注意到,您必须解决更复杂的问题,例如查找对等方的公共IP地址(即,发现对等方)。

If this becomes too complicated, you'll want to explore P2P frameworks, such as JXTA (or JXSE, its implementation in Java). 如果这变得太复杂了,您将需要探索P2P框架,例如JXTA(或JXSE,其Java实现)。 By the way, JXTA/JXSE works for peers with a private IP address. 顺便说一下,JXTA / JXSE适用于具有专用IP地址的对等方。 I have heard that JXSE has been ported successfully on Android too. 我听说JXSE也已经在Android上成功移植。

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

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