开发者

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)? We are able to successfully do this over our local开发者_Python百科 network, but not over the AT&T network.


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.

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. Enter Session Traversal Utilities for NAT, or "STUN" for short. 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. 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.

If the above framework isn't enough, you will have to look into providing a well-known (i.e. on the wide-open Internet) relay server to mediate connections between the two devices. This is the method that is generally employed by services like Skype, Hamachi, Xbox Live and others. Good luck!


I am not a specialist of the iPhone, but that pretty much depends on the transport layers available on the iPhone. If UDP and TCP are available, then there is a chance. 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).

You could easily implement a listener for UDP and implement some boiler plate code to establish remote connection. But, you'll quickly notice that you'll have to solve more complex issues such as finding peer's public IP address (i.e., discovering peers).

If this becomes too complicated, you'll want to explore P2P frameworks, such as JXTA (or JXSE, its implementation in Java). By the way, JXTA/JXSE works for peers with a private IP address. I have heard that JXSE has been ported successfully on Android too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜