Image title

In the previous article (But what’s Meteor?) I made a overview about Meteor, now let’s see a little more of each item of an application Meteor architecture, starting with EJSON and DDP.


EJSON is a JSON extension that supports most types eg Date (Javascript Date), Binary (Javascript Uint8Array or EJSON.newBinary) and user-defined types (EJSOPN.addType), an example is the Mongo.ObjectId. JSON by itself, does not provide this kind of support.

Some examples:

[code language=”javascript”]

EJSON.stringify ({When: new Date})

”{“ When “: {“ $ date “: 1412884295442}}”

EJSON.stringify ({imageData: new Uint8Array (10)})

”{“ ImageData “: {“ $ binary “,” aaaaaaaaaaaaaa == ‘}} “

EJSON.stringify ({_ id: new Mongo.ObjectID})

”{“ _id “: {“ $ Type “,” oid “,” $ value “:” 34c420c028fb169c31041ab0 “}}”


Another important feature of EJSON is your stringify method, when used with the option {canonical: true}, unlike JSON, ensures that the output values are always the same for a given input value.


DDP (Distributed Data Protocol) is the Meteor’s backbone. It’ss a communication protocol based on JSON (EJSON) used for communication between client and server. The current implementation of Meteor is based on WebSockets and SockJS. SockJs is an emulator of WebSocket that Meteor uses when Websockets is not available, in other words, when using older browsers.

What can I do with it?

You can execute remote methods invocations against the RPC server (Remote Procedure Call).

You can subscribe to ‘data sets’ to stay informed in real time about any change that happens within these sets. What do you mean?

For example, when you, client, accesses this blog, a subscription happens:

Meteor.subscribe (‘posts’, this.language (), this.findOptions ());

You subscribes (sub) under “posts”.


Server responds with the data found (added).


Server tells the client that has sent all (ready).


After that, if any changes happen within that set of data, such as a new post, “you”, you will be notified.

Another cool thing is that client and server do not know who with they are talking, they just know they are speaking DDP, in other words, clients and servers do not necessarily need to be Meteor applications. An example would be a native mobile application talking to a Meteor server using DDP.

An example is the meteor-ios, written to integrate iOS native applications with Meteor servers using DDP. Here’s a snippet of code into Swift:

[code language=”javascript”]

let Meteor = METCoreDataDDPClient (serverURL: NSURL (string, “wss: //servidor-meteor.com/websocket”))


class AppDelegate: {UIApplicationDelegate

func application (application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

Meteor.connect ()




When a Meteor client is loaded, a new connection to the server is established.

Meteor.connection = DDP.Connect (DDP_DEFAULT_CONNECTION_URL);

And it is through the object returned by DDP.Connect that the client communicates with the server, two of the most used methods of this object are call and subscribe; apply, status, reconnect, disconnect and methods are set directly on the Meteor namespace, that’s why whe can subscribe using Meteor.subscribe and not Meteor.connection.subscribe.

Observing messages exchange.

A very useful tool to see this happening is the DDP Analyzer. Installation is very simple.

[code language=”shell”]

npm install -g ddp-analyzer


After installation it’s just start the proxy

[code language=”shell”]



And export the environment variable DDP_DEFAULT_CONNECTION_URL

[code language=”shell”]

export DDP_DEFAULT_CONNECTION_URL = http: // localhost: 3030


What you are doing here is telling to Meteor client, to connect to another server, in this case

localhost: 3030

Another variable that was not mentioned in the DDP Analyzer documentation but, that helps  viewing of DDP messages exchange is DISABLE_WEBSOCKETS. Export this variable to true (optional)

[code language=”shell”]



Okay, now it’s just start you meteor application to view the messages exchange client and server.












Allan de Queiroz

Allan de Queiroz
London based software engineer

XServer forward from Linux text mode for Headless purposes.

Hello, this post is about XServer forward from Linux text mode, **not ssh forward, anything related to VNC** or things like that.Recently...… Continue reading