What would be the best method to achieve realtime device to device communication within an application? I've b开发者_如何学Pythoneen experimenting with the Apple Push Notification Service but find it spotty at best for realtime messaging. Is there a way to utilize sockets for this or am I just stuck into using the APNS?
If you are a beginner, use GameKit.
When you get sick of that, use AsyncSocket.
GameKit is so simple a child can use it; AsyncSocket is probably the most beautiful library in all of networking on any platforms - incredibly easy to use.
In both cases, you will first use Bonjour (two lines of code) to "find" the other device.
Here is the full explanation... Tablet(iPad/Android)-Server Communication Protocol
Critical secret knowledge about GK you will need...
Client/Server GKSessions
Another quick summary ...
Most effective way to do networking on Mac/iPhone?
For the record, APNS has absolutely nothing whatsoever to do with what you are trying to achieve! Utterly forget about APNS.
WHAT IS THE RADIUS? -----------------------***
Please note that BLUETOOTH ONLY WORKS over about twenty feet. (Ten meters.)
Please note that for a local WiFi connection, you must both be connected to the same local WiFi hub. WiFi hubs have a range of perhaps 20 meters only, say one house and the next house only (depending on how thick the walls are).
Please note that: IT IS NOT PHYSICALLY POSSIBLE TO CONNECT TWO COMPUTERS (OF ANY TYPE) OVER A COUPLE OF MILES.
There is no such networking device. (You could perhaps build one using say "ham radio" but to be clear it would be a completely novel, new research project that would take a large company years to complete.)
There is absolutely nothing that works like that - I'm sorry to tell you the bad news.
The ONLY two possibilties are Bluetooth and WiFi, and they work only over about 20 and 30 feet respectively.
So how do you connect two remote computers like that? The answer is, via the internet.
The only way to do it is with an internet connection. There is no 'direct' connection possible with any existing technology.
If you need to know more about how to connect two computers (say two iPhones) using the internet, you will probably have to ask a new question! You will be pleased to know it is very easy and will cause you little trouble.
Note that both iPhones MUST have a good solid internet connection. If they are more than say 30 feet away from each other, the ONLY way to connect to iPhones is via the internet. THey must each have a good internet connection, or there is no possibility.
I hope this helps clarify things!
You can use GameKit's peer to peer services (bluetooth) Gamekit how to do p2p wifi connection in iphone
Check out Apples GameKit framework GameKit Or a sockets based networking look at AsyncSocket which also includes an iPhone demo.
精彩评论