How does iPhone app communicate with other devices? - iphone

We bought a Grace wifi radio. Grace has a cool iPhone app that connects to the radio and lets you control it.
My question is.. how the heck does this work? How can the iPhone connect to the radio and then control it??

I can't find detailed technical information on Grace's side, but, if I were asked to design something like this, I'd have the radio advertise a service on its wifi LAN via zeroconf (also known by Apple's trademarked name, bonjour -- an app on the iphone (or any other node on that wifi LAN) can then easily find the radios on the same LAN and chat with them through whatever protocol Grace has defined for the purpose.
Edit: from the scarce crumbs of docs on Grace's site it seem they may have chosen UPnP instead of Zeroconf -- ah well, see here for a (possibly biased, but solid) analysis of why they should have chosen Zeroconf instead!-)

Are you asking coding specifics or just an overall concept of what's going on? The actual networking stack behind these operations can be quite complex.
Your Grace wifi radio will have created a server which the iPhone has connected to on your wifi network, from this point onwards it's a simple client-server relationship, with the iPhone sending data to the radio each time it sends a command. Because of this, if your iPhone is not on the same wifi network it will not be able to control/find the radio.

Most likely, the WiFi radio listens over a fixed UDP port. The iPhone in turn sets up a UDP connection by broadcasting the network (on IP 255.255.255.255) on that port. The radio will respond and a connection will be established.
This is complete speculation; I have no idea how it actually works. No doubt there is plenty of documentation on this.

Related

How can I send simple data from an iPhone to another iPhone, or an Android?

I'm just getting started with mobile development, and after considerable searching I'm still confused about sending a message from my iPhone to another or an Android. For instance, in building a simple Tic-Tac-Toe game, if I want to notify the other phone of a move, what is the best way to do so? Wifi, bluetooth, 3G? And how?
Many methods seem to point to communicating through a web server, but I'd rather send them directly from phone to phone if possible. (this is for native apps of course)
If you don't want to have a server (or even if you do! It depends!) it sounds like you will want to use TCP sockets. Apple doesn't have a generic bluetooth API to use with iPhone-to-android communication and you'll have TCP access anyway with 3G. A 3G network connection is very similar to wifi and you should be able to check for the difference as needed with little change to your overall networking code. I'm not sure if bonjour is supported on android, but I bet someone has ported it for similar reasons already, and it is supported in iOS. Apple has a networking section for iOS that you may find informative.
Additionally if you want to stay within the iOS device only realm you could use GameKit to communicate via bluetooth.
Hope that helps some.
The easiest way is to create a web server with an API and the clients poll the server for new moves (or the server pushes the client an update). This is the only way you're going to be able to do it over 3G unless you can figure out the IP addresses of both phones (do phones even keep the same IP address for a long period of time?) and open up sockets between them and let one phone be the server and the other be the client (could cause potential cheating).
WiFi is not always there - by limiting your users' options to areas with access points, you'll lose sales. Not sure about Bluetooth - how prevalent is it on handsets, how much of the API is exposed. Your best bet, IMHO, is 3G. With some kind of a central presence server (Web or otherwise), with optional proxying. Read up on peer-to-peer networking.
As far as i know does the iphone only support incoming messages over push notifications.
This means, that you have to update the information, by requesting it from web services etc.
The bluetooth API of the iphone doesn't support this either.

How does Bonjour Over Bluetooth Work

Can anyone explain how bonjour works over bluetooth from iphone OS 3.0 onwards?
The documentation says the Bonjour API's used in the application just works even if Wi-fi is off and Bluetooth is on. It also says , a Bluetooth PAN is established and hence IP address comes into picture.
But Bonjour (based on mdns) requires multicast to work. But , Bluetooth PAN (piconet) works on a master-Slave concept. Any data to be exchanged between peers has to go to the master first and then the master forwards to the all clients. Moreover there is a restriction on the number of slaves in piconet i.e., 8. that means bonjour over bluetooth has a limitation that it would work for a max of 8 devices?
Apparently, it's PANU to PANU communication. So the limitation is actually - one-on-one communication. If you use Bluetooth Explorer, included with Xcode, you'll see the iOS device presents a service with ID 0x1115. Since there is no GN nor NAP nodes in the connection, only two devices can participate in the connection.
Bluetooth Explorer also shows various custom fields that serve to exchange metadata about the connection. See my somewhat related question for an example of the service announcement.
I have only been able to get this service to appear when using GameKit, on both iPhone 3G with 4.2.1 and iPad with 5.0.1.
I know nothing about Boujour and iPhone... Perhaps Bonjour just sees the TCP/IP network and multicasts on to it -- regardless of whether the IP network is over bluetooth or WiFi or FooBar...
IIRC PAN just forms a point-to-point link to the PAN peer and, thus if the peer is an access-point (rather than just another end-node) it it it that will handle multicasting the packets.

iphone tcp/ip via accessory port?

I'd love to be able to mod the iPhone tcp/ip stack to route packets over the accessory port either serial or better yet USB or Firewire...
The applications I'm researching wouldn't be able to use WiFi, 3G or bluetooth...
Custom apps could be written to use the serial port available via the accessory port, but it would be nice to support generic apps that need network access.
I haven't tracked down much info relating to this, anyone have thoughts??
About the only way this could work would be to Jailbreak the device, and do some quite low level hacking. OS X supports NKEs (Network Kernel Extensions) that would allow you to introduce a new network interface. I don't know if the iPhone OS has these (as there's obviously not much information on it - it's supposed to be a black box). Even if it did, you'd have to make your KE lie and claim to be e.g. the Wifi device, as many applications will probe for network availability by searching for the Wifi interface.
Basically, I think this is an untenable idea. You can use the External Accessory APIs to allow your custom apps to use your dongle as a network service provider, but you can't use it to provide a new network interface. If you want this kind of open, extensible platform, then the iPhone is not really the right platform.

Forcing a WWAN connection on iPhone, even when Wi-Fi is available

I need to make a network connection over WWAN (i.e. the mobile network) on an iPhone, even when the device is connected to a Wi-Fi network, however I can't find a way to do this.
I've tried going down to the socket level and iterating through the available interfaces, however when connected to Wi-Fi, the WWAN interface (pdp_ip0) disappears.
The solution needs to be App Store safe.
Enumerate the network interfaces, you will see that when you're connected on both wifi and 3g, there are 2 with different local ip addresses. You might be able to use one vs the other by forcing a bind of your socket on the right interface before sending the data. The kernel which tries to find the best interface to route your packet should be happy with your choice.
Disclaimer: I have not tried this, this is just a suggestion.
Perhaps you can use the Reachability code to determine if Wi-Fi is enabled, firing a UIAlertView to warn the users to quit the app, open the Settings app and switch off wireless manually. Not ideal, definitely.
There is no supported way to to do this. You need to tell the user to turn off the WiFi connection since "It's a non-negotiable operational requirement for the service the app needs to connect to."
In this scenario, the user is not likely to kill you with bad reviews if you are clear about why they have to disable WiFi.
-t

How to list all devices in my wifi range in iphone

I am using the reachability code from apple to find if my iphone is connected to the wifi. Next i would like to list all the devices that are in my wifi range. How should i do this. The other devices do not publish any service. I want to detect all devices in my wifi range and send that device a request for tcp connection.
If a device does not advertise its presence and is not otherwise active, TCP/IP does not give you a way to "detect" it. If you can identify your subnet (which has nothing to do with a "wifi range", whatever that may be), you can try connecting to each possible host in it on all possible ports -- this is generally considered an attack (what legitimate reason could you have for such a port scan?), so, if you're detected trying this attack, be prepared for the consequences.
As #Alex says, even if you could find devices that weren't advertising, what's the point? You can't most likely do any adhoc communications with them. Instead you'd need to find copies of your application running on connected devices, and your app needs to advertise.
Take a look at Gamekit sample projects which will give you bluetooth connectivity, and you could dig into something like Jens Alfke's MyNetwork and Blip libraries for tcp/wifi. http://jens.mooseyard.com/2008/05/blip-come-n-get-it/