Friday, May 27, 2011

What We've Got Here is...Failure to Communicate: Bluetooth, Android, and iPhone

I'm disheartened and exhausted now, after trying to break ground on a new game that would involve peer-to-peer networking among a number of Android and iPhone devices.

What I want is to have an app that would install on tablets (e.g. Xoom, iPad) and act as a server. Players would connect to the server with phone-sized devices and exchange information with the server.

My first inclination was to use bluetooth. Well, just getting two test devices connected to a tablet is something I haven't been able to accomplish. The BluetoothChat example in the Android SDK enables connection and communication between two devices, with a single app that can function as either the server or client. I've tried to modify this app into two distinct apps: a dedicated server and client, and that works fine. But attempting to connect a second device has proven undoable so far.

I made a couple of modifications to the example code so that the AcceptThread continues to listen, even after the first connection is made (the example stops listening after the one connection is made, because it only needs to establish connections between two devices). I created an ArrayList to handle the multiple connections. Each time a new connection is attempted from a remote device, a new ConnectedThread is created and added to the list.

The first client connects just fine.

When the second client attempts to connect, the connection fails. The log output is:

D/BluetoothEventLoop( 140): Device property changed: property: Connected value: true
I/BluetoothService( 140): ACL connected, mAclLinkCount = 2
D/BluetoothEventLoop( 140): Device property changed: property: Connected value: false
I/BluetoothService( 140): ACL disconnected, mAclLinkCount = 1

So it looks like the second connection attempt is successful, but then it is immediately disconnected. This looks like it's happening at a low level, outside anything the code is handling. This happens with a number of different types of test devices, so I don't think it's due to a particular firmware or hardware issue.

At the Lafayette Mobile Developer's meetup last night, we talked about bluetooth communication between Android and iPhone devices. I hadn't even looked into the iPhone side, but I should have known that they basically don't have a bluetooth API for iOS. Or rather, they don't have one that allows Apple devices to talk to non-Apple devices. Bluetooth on iOS can be done through GameKit. This thread on Stack Overflow suggests that it would be possible to spoof the GameKit functionality on Android to allow an Android device to talk to an iOS device, but I can see no indication that anyone has done such a thing.

I noticed in the same thread that the Bump API is mentioned, and I always assumed that it used bluetooth or some other kind of local connectivity. Nope...it uses a device's data connection, sends information to the cloud and syncs up devices based on their GPS position, which is kind of cool, but it also means that devices without a network connection (e.g. wifi only devices) can't use it. This is a deal breaker, because a lot of tablets are going to be wifi only.

So what about wifi? Well, on that front it sounds like Android does not support ad-hoc peer-to-peer networks, at least according to this post.

I find this ridiculous and depressing that these devices are all equipped with multiple ways to communicate locally, but in both cases (Android and iOS), the SDK functionality doesn't allow a way for them to talk to one another enough to write a simple app that pass something like a string between devices. NFC technology might enable local communication effectively, but it doesn't sound like NFC capabilities are coming to iPhone anytime soon, and they may be locked down if/when they do.

At this point I'm not even sure that a wifi-only tablet and multiple phone client app is going to work. It will likely work fine within a given platform, but not cross-platform, and that is extremely limiting.

Bah.

Thursday, May 12, 2011

Google I/O 2011

Google I/O 2011 wrapped up yesterday. Overall it was another great experience. I attended for the first time last year.

First off, I/O had a much bigger Android footprint than last year. That might have something to do with the fact that the platform has exploded in growth. But this year they devoted an entire floor to Android. Some pics...

Here's me showing my love for the green guy:



Here you can see the giant Android figures all over the place:





They even tore up the carpet on the third floor and put down custom Android carpeting. There were autonomous Android-bots roaming around bumping into people and chirping as well.

And the first day keynote focused on Android, rather than teasing us until the second day, like last year.

Goodie-wise, they gave us all a new Samsung Galaxy limited edition 10.1" tab, which is pretty sweet, though I hope they don't release the software in this condition when it goes live. I've found some page rendering in the browser (ironically, the acceptance to Google Music Beta didn't render properly on my tab). I couldn't find the books app, either natively installed or on the market. And I couldn't find a native video player. When I uploaded an mp4 to try it out, I could not find it via the file explorer or any other way. So I basically couldn't figure out how to play a video that I put on the device. Unlike other Android devices, when you attach it to a PC it either needs to be in USB debugging mode, and if that is toggled off, you can then mount for file transfer. But every other Android device allows you to do both when attaching to a PC. This is pretty weird. We're supposed to get an OS update in "a few weeks", so hopefully that will clear up a lot of these issues.

We also got invitations to Google Music Beta. I'll discuss that when I play around with it more. We got a promise that we'd get information on how to claim free ChromeBooks, laptops running the new ChromeOS. I'm somewhat skeptical about this paradigm, but I'm still looking forward to trying it out. And finally, we all got mobile wi-fi hotspots with 3 free months from Verizon. Thanks to Google and the manufacturers!

Some people also received the new Sony-Ericsson Xperia play phones if they were lucky enough to attend a particular session on Day 2. I think this was a pretty bad idea. First of all, second day Android sessions had very severe capacity issues, so many devs, including myself, weren't able to attend most of the Android afternoon sessions, including the one with the giveaway. In fact, I think it's possible that rumors of a giveaway may have created the congestion. So this was bad for the two main reasons that it possibly kept some developers from attending sessions they wanted to attend, and it probably engendered some bad feelings from devs who selectively received free phones.

I actually heard another rumor that HTC wanted to give away phones to everyone, but Google thought that level of hardware giveaway would be too extreme. Ah well. So I didn't get a phone, which I need to upgrade. And unfortunately the Nexus S is not available on Verizon. So I'll probably end up getting a Thunderbolt, or possibly switching carriers.

Anyway, I had a good time, and got to talk to a lot of nice folks from Google, as well as other devs. I didn't meet up with nearly as many devs as last year. I think they could do a better job of facilitating networking between devs with common interests, and I told them as much in my feedback note.

So I'll most likely be there next year as well.