Iphone Power Unleashed - Part 2 - Networking

Sep 29, 2009
Shawn Simon

Next in the series of IPhone application development. First was graphical implementation, now distributed networking.


Welcome Back Hugo Munoz as my Guest Blogger.


Designing mobile distributed applications implies formalizing the development process to face a lot of challenges in terms of communications, patterns, middleware software, security among others. The market of mobile applications is growing rapidly. Mobile terminals such as iPhone and Android are capable of running rather complex applications, due to the rapid process of hardware and telecommunication technologies, this could mean only one thing �The world is becoming mobile� and we need to be ready to accept the challenge of bringing creative and technically unique software.

Before starting I have to mention that my inspiration for this two iPhone blogs was a little application that comes with the iPhone SDK called �WiTap� that demonstrates simple networking between two iPhones/iPod Touches using sockets in case you are not registered in the iPhone developer program here is a YouTube video that shows the application: http://www.youtube.com/watch?v=SzDCAMIy24w

To be honest my intention was just to do some testing in matters of networking between two devices, but WiTap already showed me that, so I decided to take the next step in the creation of a real distributed cross device / platform architecture capable to work over the internet in a reliable and secure way.

The first concern that came to my mind was finding the appropriate communication protocol for a cross device solution, after so many days of failed tests my patience was arriving at its aim then �STOMP� came to the scene which is a very simple and easy to implement message queue based protocol designed pretty much like HTTP; the server side may be hard to implement well, but it is very easy to write a client to get yourself connected, also googling a little bit I found an open source Stomp connector for ObjectiveC which dramatically simplified this first task, I just downloaded the library then plugged it into my XCode Project and worked smoothly.

By this point the communications was happening but in a crude way, just sending text like messages from the client to the server broker, so the next big challenge was adding the ability to serialize and transmit objects thru stomp, for this I initially thought in two options the first one was embedding XML into the stomp message or make my application speak JSON, I took the second approach for this test because I found a very good open source JSON parser for objectiveC, I just wanted to be practical and JSON is faster than XML.

The final piece was designing a restful API to transmit my �Simon says� movement sequences between players, here I did a very simple Java Server Objects implementation which publishes JSON messages to the STOMP broker then it broadcasts to the subscribed clients. Here is a basic diagram of the solution:

As you can see this is a cross platform / device solution, off course the backend could be any technology you feel comfortable with for example Windows Communication Foundation (WCF) with a custom binding implementation to speak �STOMP� in the mix, the same applies for the client side, we can have both Iphone and an Android devices working together in the same application sharing the same backend.

I hope you found my little experiments interesting and thanks for your time reading this blog.