Is it possible to connect iPhones through NAT traversal techniques over 3G for peer 2 peer gaming - iphone

Is it possible to connect an iPhone to another iPhone or any other network client talking that game's protocol.
I was thinking that I could use the same NAT Traversal technique used in the XBox 360 to host games on users XBox's through Firewalls.
For NAT traversal to work effectively I'd have to have a central server that would allow clients to "broadcast" that they were hosting so that another client could initiate the NAT connection. In the link provided this is called relaying.
Is there any inherent limitation of the US AT&T 3G network that will block the NAT traversal techniques (would you be limited to wifi firewall NAT traversal)?
NAT Traversal Projects:
- PJSIP - providing NAT traversal functionalities by using standard based protocols such as STUN, TURN, and ICE.
- Freecast using Apache MINA Java network library for NAT Traversal

iPhone OS 3.0 will have an API for multiplayer gaming and connectivity with over devices in your immediate area,
"You can find other iPhones and iPod Touches in a given area that are playing the same game as you; Forstall gives the example of two kids in the back of a car. iPhone 3.0 will automatically discover other applications over Bluetooth, and there's no pairing. "Completely seamless," he promises. Bonjour is the back-end technology behind this, and it's not just for games"
Sources: CNET Live Blog, and the Apple Special Event Quicktime Video It's about 20 minutes into the presentation.
If you are going for something more than playing with nearby devices, you will probably run into problems with bandwidth caps on the 3G network as well as latency issues depending on where users are located. Boonies with very sporadic 3G coverage vs. downtown major city USA with multiple cell towers concentrated in a small area. You may also run into a problem with AT&T depending on how much data the game is sending and receiving from the phone over the 3G network since multiplayer games require the players and the server (even if it's a player acting as one) to send information back and forth constantly. Interesting idea though!

Yes, it is possible.
Eyeball Networks has released a SDK for iPhone NAT Traversal

AT&T appear to use a randomized symmetric NAT - this means traversal is not possible between 2 iphones on their network without a relay server. What I don't know is if iPhones on AT&T can reach each other directly using their private addresses if they are on the same part of AT&T's network, or if there is some firewall. Last time I checked TMobile used a port restricted cone NAT, so traversal is possible between iPhones on TMobile, but not from TMobile to AT&T.

3G is a big problem. If you'd like to establish UDP connections with other players over 3G, you might want to try this technique:
https://drive.google.com/file/d/0B1IimJ20gG0SY2NvaE4wRVVMbG8/view?usp=sharing

Related

Bluetooth vs. Wifi for iPhone data transfer

I'm working on adding sharing support to my iPhone app. Right now, I'm using Bonjour to create plain TCP connections over a wifi network. This works great, except that it turns out that many wifi networks in the real world (for example, those at Starbucks and other chains) forbid Bonjour publishing and discovery over their networks.
So that limits the usefulness of sharing, since one of the use cases we imagined was that people could bump into each other where wifi was available and seamlessly share data with each other.
Is Bluetooth a viable alternative for this? We're sending large amounts of data (PNG images) over the wire, so latency and throughput might be one issue.
(I'm also interested in any other ways to make it easy to transfer data between two iPhone apps)

TCP hole punching on iPhone

I have done a bit of reading, and although I'm new to iPhone networking I was wondering if a TCP hole punch is possible for connecting two iPhones through NAT. I also read some helpful things about uPnP and hairpinning but I'm not to familiar with those at all, so if anyone has any ideas as to whether or not this is possible.
My goal is to be able to connect multiple iPhones over a large range (so it may be better to switch to some type of GPSR) but for now I'm only working with two iPhones and 3G NAT Traversal seems the simplest and most reliable in theory.
nat traversal is generic term used to connect two node directly with the help of rendevous server.Node can be any thing computer, smart phone or any other device.as far 3g is concerned it is one of the medium to transfer data nothing more .
Hair pin comes in to picture if your peer devices under same NAT uses public ip to connect each other because some router does not support hairpining like cisco router etc.This can be overcome if you use private IP instead of public IP.I can't say any thing about hair pinning in your case, since i don't the technical details about your network.
Update your question with technical details like kind of 3g you are using.then only I can say about hair pinning on 3g.
I have implemented udp/tcp hole punching using on 2g.I used three PC(one rendevous server and two node) to do this.
develop a rendevous server program which will run on one pc.the program should be capable to exchange public ip of two iphone device.
develop a client program install in iphone.Connect iphone to server this will expose public ip of iphone to server.repeat same process for second iphone. Now server will exchange public ip/port to both iphone.
now each simultaneously start sending packet to each other at the same time this will punch hole in NAT.
detail about hole punching can be found on this http://www.brynosaurus.com/pub/net/p2pnat/
Better try with UDP hole punchcing which is easy to develop.TCP hole punching is bit tricky.Once you implement UDP Hole punching it is easy to to implement TCP hole punching.
Learn about STUN,ICE,NAT type,Nat Maping
https://www.rfc-editor.org/rfc/rfc5389
http://en.wikipedia.org/wiki/Network_address_translation
Cellular networks use Large Scale NAT. There are only three ways to get around it.
Don't use cellular networks or use a home/Wifi connected to a cellular network.
Get a TURN server.
Use multi-UDP hole punching (advanced technique). For Multi-UDP hole punching, try:
https://drive.google.com/file/d/0B1IimJ20gG0SY2NvaE4wRVVMbG8/view?usp=sharing

iPhone Gamekit peer with a desktop peer

I am looking for a way to establish a wireless connection between an iPhone and a desktop client. Gamekit looks promising but all the examples / documentation only explain iPhone to iPhone.
Are there examples / documentation for an Gamekit peer on the desktop (cocoa or java)?
What are the alternatives without doing to much low level socket programming?
The iPhone emulator does not run these bluetooth p2p connections. Hence, it can only be tested with real hardware.
It is a little confusing because the GKSession reference talks only about being a way to connect peers over bluetooth, while the GKPeerPickerController states "can be configured to select between Bluetooth and Internet connections." However there's a clear note there that they're not really going to help you with internet based connections.
This is unfortunately a non-answer, but...
GameKit is an abstraction of the bluetooth and wifi networking layers, allowing a specific set of protocols for communication between two devices -- to communicate with a desktop client, you would need to replicate all of the GameKit functionality on the desktop, since there is no comparable API on the desktop. This would not be a simple undertaking.
I would highly suggest developing something over bonjour, as #Jordan suggested. Bill Dudney's project (blog article). It's a great place to start.
Citing Game Kit Framework Reference's Features paragraph:
Peer-to-peer connectivity allows your game to create an ad hoc Bluetooth or wireless network between multiple iPhones in the same local area. Although designed with games in mind, this network is useful for any type of data exchange among users of your app. For example, an app could use peer-to-peer connectivity to share electronic business cards or other data. This functionality is only available on iOS. You can also get the same functionality using Game Center.

What is the range of bluetooth and is it strictly 1:1?

Does anyone know what kind of range can you get from the iPhone
bluetooth? Also, would the connection be strictly one to one? I know you
can choose from a number of peers to connect to but once the connection
is established, it seems you can only transfer data between one peer? So
basically, is it possible to create some kind of "multiplayer" experience?
Just answering the range part of your question...
The 10 meter figure for class 2 devices (of which the iPhone is an example) is very much a guideline.
The range of a Bluetooth device is limited by many real world factors. The 2.4 GHz radio frequency used by Bluetooth is strongly absorbed by water. For example, consider an iPhone connected to a Bluetooth mono headset. If the headset is in one ear and the iPhone is in your trouser pocket on the opposite side of your body, then there's a lot of water between the two devices. This will often cause a significant amount of packet loss in practice (you can hear this in the audio being carried). So, in this case, the range is about one meter.
At the opposite extreme, two class 2 devices separated by nothing more than clear air can get ranges of hundreds of meters.
Other factors that influence things are:
Interference - Lots of things use 2.4 GHz. WiFi, for example can cause problems.
Antenna design - Space and cost constraints often mean that the antenna design is sub-optimal. I don't know how good the iPhone is in this respect.
Walls - Generally walls attenuate Bluetooth signals. However, sometimes they are useful reflectors.
Quality of hardware - Some chips work better than others. Even different firmware revisions of the same chip may perform differently. Different versions of the iPhone probably have (or will have) different chips in them.
Protocol - It is possible to work around poor signal quality with error correction and retransmission. Even if the iPhone SDK forces you to use a particular protocol, careful design of your application can make a difference.
So, in summary, you should probably do some real world tests.
The connection is one-to-one, but you can create an adhoc network with one of the phones acting as the master/coordinator. The other phones would route all their communication through the master/coordinator.
One device can theoretically connect to 7 devices. according to the master-slave role, the device can multiplex between each of them giving the user an impression that you are connected to all of them simultaneously. Bluetooth specification does not stop you from doing that.This is theory.
Now for the iphone, whether it can connect to to more than one device can only be answered by apple or someone who knows the iphone bluetooth API. But I am pretty sure the bluetooth chip inside iphone should be able to connect to more than one device.
Range is essentially going to be good enough for a normal sized room to be covered. It can be longer or shorter depending on environmental circumstances, but remember that bluetooth was created to implement short range connections.
A bluetooth device can be part of a piconet of eight devices, one master and up to seven slaves. The slaves cannot communicate with each other, they must talk through the master, think of a star topology with the master in the center. The iPhone SDK has a GameKit framework that can be used to create the network for multiplayer games. Go to developer.apple.com at look at the GKTank and GKRocket sample code to see how it's used. These games only support two players, but the GameKit framework supports more. Look at the app store and you will see games that have four or more players.
Hope this helps to get started.
Apple iPhone 3G has a Class 2 bluetooth module. Class 2 Bluetooth devices have a communication range of 10 meters.
At a given instance a device can connect to just one device because it follows a master/slave communication model. But still we can perform a multiplexing. So we can virtually connect to more than 1 device and by rapidly changing the connected device.
I found a good article here. It explains bluetooth very well.
According to the my knowledge, multicasting is not impossible with bluetooth. So gaining a multiplayer experience is NOT impossible.
The bluetooth in the iPhone is Class-2, with a 10-meter range, approximately.
Unfortunately I can't answer the other parts of your question.
One device can be connected up to 8 others. It all depends on the iPhone bluetooth API (which I don't know anything about), but with Bluetooth itself you could then send data to multiple devices.
I tether my iPhone to my laptop over bluetooth every day, and I seem to remember having done that at the same time as using a bluetooth headset. YMMV.
It’s the latest incarnation of Bluetooth, the wireless device-to-device technology that allows your phone to talk to headsets, car stereos, keyboards and other devices directly, without the need for a router or shared wireless network.

iPhone to iPhone communication

I'm kind of curious how I should approach a problem with iPhones and communication between two phones.
I have an idea for an application that needs to send data between two known phones. The problem is that the data could be very small or very large. I want to have intermediate storage on a server and a messaging layer, but I want there to be performant means to communicate between devices for shorter, unimportant messages.
You always hear about networking and client to client communication with popular platforms and protocols, but I'm curious what people's thoughts are on doing p2p style communication with an iPhone.
I'm pretty sure it should (and can) be treated as just a simple addressable machine... so I would have to build NAT traversing network code into the iPhone itself. A thought I had would be some sort of UPnP situation where I would ask to NAT a particular port for communication to the devices... but I guess I could just as easily turn it into a polling situation.
Granted, I understand that Apple will have a "push" mechanism for developers eventually but I want to get the app out the door before hand...
Just curious about thoughts on this type of thing... any thoughts on multi-player game situations would also directly apply to (and benefit from) this question.
Have you given the WiTap sample from Apple a try? It addresses the issue of discoverability (via Bonjour) and connectivity (via basic TCP). It may not be as robust as what you are looking for, but it's worth a look:
http://developer.apple.com/iphone/library/samplecode/WiTap/index.html
Look at the docs for Game Kit in the iPhone 3.0 SDK. It allows iPhones to connect to one another locally with Bluetooth, or via wi-fi/3G. It addresses both peer-to-peer and client-server architectures. It provides unreliable and reliable links.