Lightstreamer
SitePen Support

Comet on the iPhone: Interview with Gianluca Bertani

by Alessandro AlinoneJanuary 12th, 2009

In a previous musing for Comet Daily, I announced the public availability of iStreamLight, an open-source library for the iPhone that implements the network protocol of Lightstreamer. Basically, iStreamLight enables any native iPhone application to be a Comet client, that is, to receive textual real-time updates, pushed from the Server through an HTTP connection.

In this article I will publish a short and informal interview with Gianluca Bertani, the creator of iStreamLight, to scratch the surface of some technical details of his library and to know more about him. Gianluca is a senior software architect based in Bologna (Italy), where he works on projects for the finance industry.

Gianluca Bertani and his iPhoneAA: Gianluca, how did you decide to start working on iStreamLight in your free time?

GB: Well, I had an iPhone there on the table and Xcode here on my Mac, and I was really intrigued by the capabilities of the platform. I decided to start coding a simple example that could rely on my previous knowledge, so to approach the platform with less difficulties. I had the opportunity to work on the Lightstreamer textual protocol in previous experiences, it seemed to me to be something easy, useful and interesting at the same time to implement a client library for the iPhone, and it let me learn the platform without necessarily having to deal with all the bells and whistles of the UIKit (which is the GUI SDK of the iPhone), surely an interesting part but far away from my background.

AA: Can you explain to us the architecture of iStreamLight?

GB: Of course, but I would have to kill you after that! Ehm, just kidding. The architecture is really straightforward: the class model represents, in a one-to-one fashion, the entities of the textual protocol. So you have a “client” object, which represents a Lightstreamer server, and a “session” object, which represents an open stream to a server. The library uses a simple “listener” pattern to send the updates to the user code. The only non-trivial part has been the handling of the streaming connection: I have not been able to keep a native Cocoa URL connection alive on an infinite connection, as it seems to remain synchronously locked until the socket is closed by the server. So I had to reimplement it with direct socket streams and an independent thread loop. This way I had the opportunity to learn how threads are managed in Objective-C. It works seamlessly, anyway.

AA: iStreamLight is written in Objective-C. I think not so many web developers are familiar with this language. Would you like to outline the main concepts behind Objective-C?

GB: Interesting language, it seems to me a simple ANSI-C with an added object paradigm taken directly from Smalltalk. It has almost the same expressiveness of Java or C++, you just have to pay attention on some pitfalls like reference counting on object pointers. What I really miss from Java is the dot notation: all those square brackets tend to be quite unintelligible to me; from a quick view it seems like reading a formula on an RPN calculator.

AA: Please share some code snippet that shows how to use the iStreamLight library?

GB: Sure. This is how you initialize a “client” object to bind it to a Lightstreamer server:

LSClient *client= [[LSClient alloc] initWithServerURL:[NSURL
   URLWithString:@"http://push.lightstreamer.com:"]];

While this is how you open a stream (that is: create a “session” object) to the server:

LSSession *session= [client createSession:@"" password: nil 
   adapter: @" STOCKLISTDEMO" listener:self
   options:[[LSSessionOptions alloc] init] autorebind:YES];

And in the end this is how you subscribe to an item for the open stream:

[session add:1 table:1 group:@"item7" 
   schema:@"stock_name last_price time pct_change min max"
   selector:nil mode:LSModeMerge requestedBufferSize:0
   requestedMaxFrequency:0.0 snapshot:YES];

This provokes the following method (note that the listener is “self”) to be called with the real-time data of the “CVS Asia” stock from the Lightstreamer home page:

(void) onUpdate:(LSSession *)session
   window:(NSInteger)window table:(NSInteger)table
   item:(NSInteger)item values:(NSArray *)values {
   // ...
}

AA: Tell our readers where they can find iStreamLight, in case they would like to check it out or to contribute to the project.

GB: The project is hosted on Google Code at the URL http://code.google.com/p/istreamlight/. It is released under the new BSD license, so it is free for everyone to use, you just have to cite the author. My spare time is really reduced now, help would be really appreciated, even just a thorough test of all the features would be important.

AA: A first certified application using iStreamLight, named Shareprice, has already been released on the UK iTunes app store. Did you expect such a prompt adoption of your library?

GB: Surely not, it was a nice surprise. An even better surprise was to know that the library didn’t need any special adjustment to work for Shareprice. I mean, in the life of a software engineer it doesn’t happen so often that some software he or she wrote works reliably on the first try! :-)

AA: Gianluca, thank you for sharing this information. Keep on the good work.

GB: Thanks for this opportunity.

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
SitePen, Inc. Comet Services

4 Responses to “Comet on the iPhone: Interview with Gianluca Bertani”

  1. Gianluca Bertani Says:

    I’ve just noticed that in the third code snippet an open square bracket has been lost. Corrected it would be like this:

    [session add:1 table:1 group:@"item7" schema:@"stock_name last_price time pct_change min max" selector:nil mode:LSModeMerge requestedBufferSize:0 requestedMaxFrequency:0.0 snapshot:YES];

    Please forgive this little error…

    Gianluca

  2. Fabio Says:

    Hi Alessandro, Gianluca

    I was wondering whether iStreamLight would work with Lightstreamer Moderator server, given that the SDK for Generic Client Development is not supported by the Moderato version.
    I am planning to use both in a non commercial app.

    thanks

  3. Alessandro Alinone Says:

    Hi Fabio,

    That’s correct. The “generic client” protocol, used by iStreamLight, is only available on Lightstreamer Presto and Vivace, and not on Lightstreamer Moderato and Allegro. This is a consequence of the original choice to segment the product into lower-end editions, only aimed at JavaScript clients, and higher-end editions, covering all the client technologies.

  4. Dmitri Tcherevik Says:

    It should be mentioned that an Ajax client works in Safari running on an iPhone just fine. I used dojo to implement a simple mobile web conferencing application that works both on an iPhone and an Android phone. Events are propagated via 3G with almost no delay. You can check out some videos here: http://www.mightymeeting.com/blog. I suppose one could use this in a native iPhone app via UIWebView.

Leave a Reply



Copyright 2014 Comet Daily, LLC. All Rights Reserved