Meteor DDP server to client specification: strange characters in the beginning

517 Views Asked by At

I'm discovering Meteor DDP protocol right now, there is not much documentation about it.

What I've found out is that Meteor server sends one character in front of every block of messages (which are sent like strings somewhy, do you know why?), like this:

c[2010,"Another connection still open"]
o
a["{\"server_id\":\"0\"}","{\"msg\":\"connected\",\"session\":\"BFWEff4389fjHFure\"}"]
a["{\"msg\":\"ready\",\"subs\":[\"fefjuihYFrvnuKOEF\"]}"]

(keys were changed)

What is the purpose of prepending this character? Where can I read more about it and about low-level DDP specification? Am I guaranteed (at least for pre1 version) that all messages are encoded in strings, and these strings concatenated into array, and each such array is prepended by a custom character?

1

There are 1 best solutions below

1
On BEST ANSWER

I think those characters aren't added in by meteor but are put in by sockjs, the module Meteor uses for websockets which DDP is built on.

  • c stands for closed (close frame)
  • o when the socket has been opened (open frame)
  • a when data is received (array of encoded JSON message)/data type
  • h hearbeat, sent every minute as a keep alive.

You don't need these for DDP. If you send them they would just be ignored.

You can have a look at more low level ops without sockjs at projects like node-ddp-client which uses faye-websockets so its a bit more raw. Data can be sent in raw stringified json too.

Reference: