Did you know? DZone has great portals for Python, Cloud, NoSQL, and HTML5!
HTML5 Zone is brought to you in partnership with:

John Esposito curates content at DZone, while writing a dissertation on ancient Greek philosophy and raising two cats. In a previous life he was a database developer and network administrator. John is a DZone Zone Leader and has posted 268 posts at DZone. You can read more from them at their website. View Full User Profile

Rocket Your Real-Time Mobile Apps with Square's New WebSocket Library for Objective-C

02.15.2012
Email
Views: 1517
  • submit to reddit
The HTML5 Microzone is presented by DZone and Microsoft to bring you the most interesting and relevant content on emerging web standards.  Experience all that the HTML5 Microzone has to offer on our homepage and check out the cutting edge web development tutorials on Script Junkie, Build My Pinned Site, and the HTML5 DevCenter.

Jack Dorsey should know something about real-time, and mobile, and awesome: he founded Twitter, and then founded Square, the little mobile device for accepting credit card payments with iPhone, iPad, or Android.

So Square should know something about excellent real-time mobile technology. Now, true real-time communication involves true multiplexing, of course; and WebSockets is the web standard for exactly that. But WebSockets doesn't even enjoy perfect desktop browser support, let alone mobile browser; so real-time mobile app developers (like Square) can't rely on the standard just yet.

So let's think about this. You could wait for the standard (which is silly); or do some Ajax long-polling (which is faking it, and not really real-time); or you could toss the browser and write your own client. But writing a whole new client for a multiplexing communication protocol is, well, a lot of work.

But Square just did just that -- at least for iOS: they wrote straight-up WebSocket client directly in Objective-C.

And it's open-source, produced in the best possible open-source way: as a solution to a very practical problem (you can imagine why a company like Square needs to worry about real-time web communication), a solution the creators then made available to everyone else:

At Square, we devote two weeks a year to fix annoying problems that are outside the scope of our normal jobs. We call them Fix-it weeks. During our last Fix-it week, we wanted to fix network debugging tools for iOS. Well, we made it happen. The plan was to talk to Chrome’s remote debugging API which just happened to be a JSON protocol over WebSockets. There were no up-to-date (hybi-17 at the time) WebSocket client libraries for iOS at the time. So we wrote one.


If you're interested in real-time communication using WebSockets, and want to take full advantage of your (increasingly large set of) mobile users, check out Square's client. Or just look at the source code, if you want to see a serious WebSocket client implementation (the spec will help with that).

 

Published at DZone with permission of its author, John Esposito.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

HTML5 is the most dramatic step in the evolution of web standards. It incorporates features such as geolocation, video playback and drag-and-drop. HTML5 allows developers to create rich internet applications without the need for third party APIs and browser plug-ins.  Under the banner of HTML5, modern web standards such as CSS3, SVG, XHR2, WebSockets, IndexedDB, and AppCache are pushing the boundaries for what a browser can achieve using web standards.  This Microzone is supported by Microsoft, and it will delve into the intricacies of using these new web technologies and teach you how to make your websites compatible with all of the modern browsers.