Seegno
Seegno
Published in
2 min readMar 21, 2014

--

Primus-Objc: a realtime framework-agnostic library for iOS

Let’s say you want to create a realtime web application and you’re into node.js. One of the first decisions you’re going to have to make is which framework to choose. There are several out there, each one of them with its advantages and disadvantages, depending on the use case. Assuming you’ve got all the requirements for your project scoped out, you will either opt for native WebSockets, Socket.IO, SockJS or perhaps engine.io.

This is where Primus comes in. It allows you to easily switch between realtime frameworks without any code changes. Not only that, it also supports plugins, message transformers and a lot of other great features (e.g., a working reconnect algorithm, latency measurements, message buffers and much more). By building an abstract architecture on top of different realtime engines, it frees you from being locked-in to a single framework.

But what if one of your requirements is iOS support? Since Primus does not ship with an Objective-C client, we’ve decided to build a port of its client part: introducing Primus-Objc.

Primus-Objc is a Primus-compatible client implementation that follows the same philosophy of the Primus project. It will connect to a Primus server instance using any of the currently supported client libraries and it will even stay connected while your application is in the background!

It has been tested for both iOS and OS X and it currently has support for SocketRocket (WebSocket iOS framework) and socket.IO-objc (SocketIO iOS framework). Contributions are welcome for other libraries!

Here’s how easy it is to connect to a server and send a realtime message:

Primus *primus = [[Primus alloc] initWithURL:[NSURL urlWithString:@"http://127.0.0.1:9090"]]; [primus write:@"hello world"];

Notice that we didn’t even specify which realtime framework to use! Primus-Objc is smart enough to connect to the remote server and determine the most appropriate framework (note: you can improve the performance of the client by telling it exactly which client library to use instead).

Keep an eye out in the coming days for more articles on how we use Primus-Objc here at Seegno.

Originally published at blog.seegno.com on March 21, 2014.

--

--

Seegno
Seegno
Editor for

Creating awesome applications with the best people and technology.