SockJS protocol

50 views
Skip to first unread message

Tim Fox

unread,
Dec 3, 2011, 7:20:23 AM12/3/11
to sockjs
Is there any document (other than the sockjs-node + sockjs client
code) that describes this anywhere?

Marek Majkowski

unread,
Dec 3, 2011, 5:56:56 PM12/3/11
to timv...@gmail.com, sockjs
On Sat, Dec 3, 2011 at 12:20, Tim Fox <timv...@gmail.com> wrote:
> Is there any document (other than the sockjs-node + sockjs client
> code) that describes this anywhere?

Tim,

Take a look at this:
https://github.com/sockjs/sockjs-protocol
and especially:
http://sockjs.github.com/sockjs-protocol/sockjs-protocol-0.1.html

This subproject tries to define the spec, but peeking at `sockjs-node`
code may still be necessary.


Cheers,
Marek

Tim Fox

unread,
Dec 4, 2011, 1:52:41 PM12/4/11
to sockjs
I don't know coffeescript (yet), so the sockjs-node code is pretty
hard for me to parse. However, the python spec test is pretty clear
and easy to follow. Instead of trying to port the sockjs-node code to
vert.x I think I'll do a "clean-room" version based on the python
test.

Thanks!

On Dec 3, 10:56 pm, Marek Majkowski <maje...@gmail.com> wrote:

Marek Majkowski

unread,
Dec 4, 2011, 4:44:03 PM12/4/11
to timv...@gmail.com, sockjs
On Sun, Dec 4, 2011 at 18:52, Tim Fox <timv...@gmail.com> wrote:
> I don't know coffeescript (yet), so the sockjs-node code is pretty
> hard for me to parse. However, the python spec test is pretty clear
> and easy to follow. Instead of trying to port the sockjs-node code to
> vert.x I think I'll do a "clean-room" version based on the python
> test.

Understandable. Let me give you a brief guide on the coffescript
implementation.

There are kind of three parts.

First, there is an entry point:
https://github.com/sockjs/sockjs-node/blob/master/src/sockjs.coffee
It's mainly a glue between a simplistic web framework:
https://github.com/sockjs/sockjs-node/blob/master/src/webjs.coffee
(which in principle is really simple, few regular expressions,
few lists of 'filters'), and various transport/protocol handlers.

Second, there are many http protocol handlers, although there
is quite a lot of things happening, the underlying logic is quite
simple. All the transport are doing basically the same, just decorating
the responses differently, according to a particular transport:
https://github.com/sockjs/sockjs-node/blob/master/src/trans-eventsource.coffee
https://github.com/sockjs/sockjs-node/blob/master/src/trans-htmlfile.coffee
https://github.com/sockjs/sockjs-node/blob/master/src/trans-xhr.coffee
https://github.com/sockjs/sockjs-node/blob/master/src/trans-jsonp.coffee

This, kindof dumb, transport are have shared logic that deals
with timeouts and stuff. This is actually the interesting (and hard) part:
https://github.com/sockjs/sockjs-node/blob/master/src/transport.coffee

And finally, there is an implementation of websocket protocol:
https://github.com/sockjs/sockjs-node/blob/master/src/trans-websocket.coffee
https://github.com/sockjs/sockjs-node/blob/master/src/trans-websocket-hixie76.coffee
https://github.com/sockjs/sockjs-node/blob/master/src/trans-websocket-hybi10.coffee
This is a surprisingly large chunk of code.

Cheers,
Marek

Reply all
Reply to author
Forward
0 new messages