2

I'm looking for a way to implement a bidirectional RPC in node.js (means that both client and server provide remote-callable procedures, preferable like json-rpc). It should be usable on top of socket.io and TCP/IP sockets for clients. I was about to use nowjs for websockets and provide a seperate API for "normal" sockets.

Now I just found dnode which claims to work with both. "It works over network sockets and even in the browser with socket.io."

I need to pass JSON objects (containing strings) to each other side. The clients will be written in JavaScript (Browser), JavaScript (Appcelerator Titanium), C# and maybe Java (Android), but there's only an implementation for Java. I read the protocol and I think it's not that easy to implement.

Also there is a method name exchange after connection is established which would be quite a overhead in my application, I don't need it as I know what I implemented on the other side (it's not a public api).

Someone has experience with it or know alternatives? I'm not sure if it's the right thing for my purpose, I need to implement CRUD and PUB/SUB.

Eliasdx
  • 2,190
  • 2
  • 23
  • 33
  • 1
    Dnode and nowjs both do method names exchange. What is your reason for not just using socket.io? – thejh Nov 09 '11 at 20:18
  • I need to answer the request which isn't that nice in socket.io (emit a new event). In nowjs you have a nice callback function. NowJS does? Didn't know... – Eliasdx Nov 09 '11 at 20:23

1 Answers1

5

Use socket.io , it has support for rooms which can be stored memory or a Redis Pub/Sub implementation. You can also namespace your sockets and provide CRUD through events.

var io = require('socket.io').listen(80);

var someResource = io
  .of('/someResource')
  .on('create', function (socket) {
    createSomeResource()
  })
  .on('read', function(socket) {
    readSomeResource(id, function(){
      io.sockets.in('roomBasedOnSessionId').emit('data', {my:'json'})
    })
  })

Here is a great walkthrough of some of the topics you'll need, including references to sockets and session sharing. http://www.danielbaulig.de/socket-ioexpress/

Chris Biscardi
  • 3,148
  • 2
  • 20
  • 19
  • 1
    Yes I'm using socket.io now. I found out that socket.io does support callbacks/direct answers. It's hidden in "how to use". – Eliasdx Nov 14 '11 at 20:57