On AIR with Flex

P2P Apps for Mobile Devices

by on Aug.11, 2011, under Code Snippets, Flex, Tech

This post is a follow up to my session at Adobe Flash Platform Summit 2011, Bangalore on the 28th of July. I spoke on Peer to Peer for Mobile Devices with the Flash Platform. Peer to Peer has been around for a long time now, but its not often you see apps making use of this immensely capable technology. My talk covered the possibilities that could come to life with P2P on Mobile, along with some demo’s. Here is the Slide Deck,

As part of my demo at AFPS, I wrote the RealTime Locator, a simple app that shares its location with every peer in a group over the RTMFP protocol. Basically, I do a Lat/Long multicast on receiving the coordinates via GPS. The other interesting aspect is the same app, with ZERO code change is deployed on 3 different platforms, Android, Blackberry Playbook, and the iOS.

Here is a video showing the app running on the three devices, HTC Desire HD, Blackberry Playbook, and an iPod Touch,
httpv://www.youtube.com/watch?v=uFF4tx82se0

I made use of the freely available non-commercial service, Adobe Cirrus, for initiating P2P connections, and the awesome MapQuest Flex library for displaying and plotting location on the map. The GPS location is represented in Red, and the shared locations in Green.

The FXP has been online for a while now, and here is the link again,
Download Source

Here is what you need to modify to get it working,

Views/MapView.mxml – Replace the value for ‘MAP_KEY’ with your MapQuest API key. Get your key at, http://developer.mapquest.com/
Controller/p2p.as – Replace the value for ‘DEVELOPER_KEY’ with your Cirrus Key. Register for a Cirrus Key here, http://labs.adobe.com/technologies/cirrus/
NOTE : To facilitate P2P connections over the LAN only, replace the value for ‘SERVER_ADDRESS’ with ‘rtmfp://’ and leave the value for ‘DEVELOPER_KEY’ blank (‘ ’).  Optionally also edit the P2P Group Name.

This application only demonstrates one of the capabilities of P2P with Flex. Feel free to get the code and build on it for greater possibilities.

RealTime Locator for Android,Real Time Locator for Android

Download Android Installer (.APK)
The above app uses a different P2P Group than what is seen in the shared FXP file. The two will not work in conjunction.

*The Blackberry and iOS apps are not hosted due to licencing and distribution constraints. Feel free to download the source and deploy on the two devices.

:, , , , , , , , , , , , , ,

25 Comments for this entry

  • Lynnhom Hsueh

    Great App,!I just want know why you do not use the Google Map for this App.You don’t need a key with Google Map.

  • Immanuel Noel

    @Hsueh, Two reasons,
    1) Google Maps SWC is not mobile optimized
    2) The existing SWC loads additional SWCs/SWFs, and fails to do so on iOS devices at the moment.

  • Immanuel Noel

    And ofcourse, the MapQuest library is mobile optimized, and works great !

  • Lynnhom Hsueh

    @Immanuel Noel, Thank you.
    I just want to add LBS feature with Flash P2P to my App.Your post is exactly what I need and I will go through it soon.
    Thank you again for your amazing tutorial.

  • Ramchandra Pujari

    Hello Thank you very much, I have attended Adobe Summit 2011 very impressed on this P2P application. I am totally new in Mobile applications. i have build this application but not getting that Red mark is not showing… please help me

  • Immanuel Noel

    @Ramachandra Can I know on which device are you testing? The Red marker stands for the GPS location. The App needs GPS capability, and will not work on the simulator.

  • Ramchandra Pujari

    new Toast(navigator, “GPS not supported!”);

  • Ramchandra Pujari

    Launch method i have selected — On Desktop: Apple iPhone 4

  • Immanuel Noel

    @Ramachandra The app will not work ‘On Desktop’ (which is nothing but the simulator) since GPS is not supported. You will have to run it on an actual device. An alternate way though, is to mock location data on the Android Emulator. Here is more on that, http://inoel.in/mockgps

  • Ramchandra Pujari

    Thank you Noel, I am totally new in this field one que for you. Apple iOS developer certificate is compalsory? i have Apple iPhone 4 with me when i have connected threw iTunes but problem is “Packaging settings have not yet been configured.” when i click Configure then they ask Certificate and Provisioning file. so what can i do? please help

  • Immanuel Noel

    Yes Ramachandra. The developer certificate / provisioning file is required for deploying apps onto iOS, or rather, for generating the installer (.ipa).

  • Ramchandra Pujari

    Thank you very very much!!! Sorry i am bothering you…iOS Developer Program
    US$99 /year is this correct ammount? Apple Online Store is unavailable, Your country either does not have an Apple Online Store or does not offer Apple Developer Products for online purchase. To complete the purchase of your program, you will need to complete and fax the Purchase Form below. is saying so i will print that PDF file and send it to FAX. so can i go…

  • Immanuel Noel

    That is correct. You will need to comply with the Apple Policies / Guidelines

  • H lotfian

    hi i want to develop a p2p application on android using cirrus 2 and perhaps action script. can you tell me what are the negative/disadvantages of developing mobile application using this two technologies? in mainly in terms of speed, connectivity speed, searching nodes shared content speed etc.

    appreciate your help
    cheers
    Hossein

  • Immanuel Noel

    @Hossein,

    I must say p2p as a technology is well positioned on the Flash platform. If I were to develop a p2p app, the only thing I would need to ensure is the availability of a RTMFP capable server (Unless i’m targeting an audience connected to LAN). As you see in the above app, data flow between the 3 devices is fast ! The delay seen is due to the GeoLocation update interval. And ofcourse, architecting your application the right way (the p2p way) would be one of the foremost considerations. And to answer you, I can assure you speed / connectivity / sharing / searching nodes is something you need not worry about. RTMFP ensures its done the best way !

  • c parks

    Hi Immanuel,

    Thank you very much for sharing your p2p knowledge. This is very helpful. I am learning how to build mobile apps using flash and Flashbuilder. I would like to run test with your demo to learn. My question to you is, does your demo require the latest Flashbulder version 4.5 to work? Or can I use version 4.0 instead?

    Thanks again.
    Calvin

  • Immanuel Noel

    c parks,
    The demo is centered around using P2P for mobile devices, for which you would need FB 4.5.
    However, you can build your own application, and make use of the P2P classes on FB 4.0.

  • Bob Cudmore

    Hi Immanuel,

    Thanks for a great App. I am a newbie to mobile app programming and I am finding your code easy to come to terms with. However, I have two problems. 1st in FB 4.6 I am getting a warning that colorDepth should be set to 16bit for optimal performance and 2nd, the map displays well in landscape but does not re-size when the playbook is rotated t portrait. Please can you tell me how to fix these two points as searches on the internet has so-far proved useless!

    Many thanks.

    bob

  • Bob Cudmore

    Hi Immanuel,

    Ok I have fixed the 16bit error it was a setting in the android element of ?????.app.xml. I am still trying to overcomen the portrait/landscape problem any help in this regard would be greatly appreciated.

    many thanks in advance,

    Bob

  • Immanuel Noel

    Bob,
    Apologies for the delay.
    Glad u fixed the 16 bit error. The portrait mode worked fine when I last tried this. Let me try to replicate your problem and get back.

  • Marcus Dobler

    Hi I am currently working on an Air for Android App in AS3! This app is running perfectly smooth on an Galaxy S2 with constant 60 fps! My new test device, a Galaxy Nexus with ICS has just arrived and the performance is very bad, unstable 40fps! Now my question is: Is this normal? Is this a problem with my code or is this an known issue of the new operating system?

  • Roman

    Immanuel,
    Great to hear you’re liking the MapQuest Flex API optimized for mobile use. Let me know any features you’re looking for.

    Roman
    Product Mgr Dev Services
    MapQuest
    @MapQuestRoman

  • Μπουζούκια Αθήνα

    Google Maps SWC is not mobile optimized

  • Geo

    Hi Immanuel,

    Thanks a lot for the nice post. But let me ask you some very basic questions: I guess, the p2p feature will work well in a typical LAN setup (without any extrenal servers), right? But will the p2p app work on a Local Wifi Network? I’ve developed a chat app, which is working fine if I deploy it to 2 different machines in a Ethernet LAN, but if I deploy this to an Android Mobile Device and a PC – both are connected to the same Wifi network – the p2p feature is not working.
    In the Mobile App, I have enabled permission for INTERNET, ACCESS_NETWORK_STATE, ACCESS_WIFI_STATE.
    Please help me out.

    Thanks,
    Geo

  • Immanuel Noel

    @GeoThe feature definitely works on all devices connected to a LAN – Including Android Mobile devices. That’s how I tested :)
    Try out the included project.

3 Trackbacks / Pingbacks for this entry

Leave a Reply

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!