Nodejs remote procedure call built on top of sockjs
eureca (easy unobstructive remote call) is a node.js RPC library using sockjs as a network layer. it's inspired from nowjs library, but intend to be simpler and provide only the strict necessary stuff to do RPC correctly.
This is the firs release, many bug may exist!
npm install eureca
node --harmony-proxies node_modules/eureca/test/rmi.js
note the usage of --harmony-proxies command line argument, this switch enables harmony proxies witch is used by eureca library (for more information about harmony proxies see this link http://wiki.ecmascript.org/doku.php?id=harmony:proxies)
it you don't use --harmony-proxies, eureca will still work using a workaround but this is not recommanded.
var EURECA = require'eureca'EURECA;//the allow parameter define witch function names are accepted in the client side.//the configuration bellow will unable server to call foo() and bar() ine the client side if the client define themvar eureca = allow : 'foo' 'bar';Server = eurecaexports; //all functions declared in this namespace will be availbale to clients//EURECA Server side functions exposed to clientsreturn a+b;;///////////////////////////////////////////////////eurecainstallapp;
since the client defined a function called foo() we can call it, but first we need to get the client instance the onConnect event provide a useful callback to handle incoming connections, we will use it to get the client instance and call foo()
eurecaonConnectclient = eurecagetClientconnid;clientfoo' From server';;
you can use the onConnect callback to keep track of your clients so you can use them later.
in the client side, the code is simpler, since we don't need to find the server instance, Eureca object will directly expose remote function
to call server side add function, all we have to do is
eurecaadd10 20; // eureca is an instance of EURECA()
we can add a callback function to get the result
eurecaadd10 20console.log'the result is ' result;;