New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

zerorpc

Package Overview
Dependencies
Maintainers
1
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

zerorpc - npm Package Compare versions

Comparing version

to
0.2.0

42

lib/server.js

@@ -92,2 +92,4 @@ // Open Source Initiative OSI - The MIT License (MIT):Licensing

// Creates a new server
// context : Object
// The object to expose
// options : Object

@@ -97,7 +99,15 @@ // Options associated with the server. Allowed options:

// (default 5s)
function Server(options) {
function Server(context, options) {
var self = this;
options = options || {};
this._socket = socket.server();
this._heartbeat = options.heartbeat || DEFAULT_HEARTBEAT;
etc.eventProxy(this._socket, this, "error");
self._socket = socket.server();
etc.eventProxy(self._socket, self, "error");
var heartbeat = (options.heartbeat || DEFAULT_HEARTBEAT) * 1000;
var methods = publicMethods(context);
self._socket.on("multiplexing-socket/receive", function(event) {
if(event.name in methods) self._recv(event, heartbeat, context);
});
}

@@ -168,4 +178,4 @@

//Call the method
var args = [result].concat(event.args);
context[event.name].apply(context, args);
event.args.push(result);
context[event.name].apply(context, event.args);
}

@@ -192,22 +202,2 @@

//Exposes an object to be used
//context : Object
// The object to expose
//options : Object
// Request-specific options that override the global server options.
// Allowed options:
// * heartbeat (number): Seconds in between heartbeat requests
// (default 5s)
Server.prototype.expose = function(context, options) {
options = options || {};
var self = this;
var heartbeat = (options.heartbeat || self._heartbeat) * 1000;
var methods = publicMethods(context);
self._socket.on("multiplexing-socket/receive", function(event) {
if(event.name in methods) self._recv(event, heartbeat, context);
});
};
exports.Server = Server;
{
"name": "zerorpc",
"version": "0.1.0",
"version": "0.2.0",
"main": "./index.js",

@@ -5,0 +5,0 @@ "author": "dotCloud <opensource@dotcloud.com>",

@@ -8,2 +8,6 @@ zerorpc-node

To install the package:
npm install zerorpc
Servers

@@ -46,16 +50,16 @@ -------

server.expose({
addMan: function(cb, sentence) {
cb(null, sentence + ", man!");
addMan: function(sentence, reply) {
reply(null, sentence + ", man!", false);
},
add42: function(cb, n) {
cb(null, n + 42);
add42: function(n, reply) {
reply(null, n + 42, false);
},
iter: function(cb, from, to, step) {
iter: function(from, to, step, reply) {
for(i=from; i<to; i+=step) {
cb(null, i, true);
reply(null, i, true);
}
cb(null, undefined, false);
reply(null, undefined, false);
}

@@ -62,0 +66,0 @@ });

@@ -26,32 +26,29 @@ // Open Source Initiative OSI - The MIT License (MIT):Licensing

var rpcServer = new zerorpc.Server();
rpcServer.bind("tcp://0.0.0.0:4242");
rpcServer.expose({
addMan: function(cb, sentence) {
cb(null, sentence + ", man!");
var rpcServer = new zerorpc.Server({
addMan: function(sentence, reply) {
reply(null, sentence + ", man!", false);
},
add42: function(cb, n) {
cb(null, n + 42);
add42: function(n, reply) {
reply(null, n + 42, false);
},
iter: function(cb, from, to, step) {
iter: function(from, to, step, reply) {
for(i=from; i<to; i+=step) {
cb(null, i, true);
reply(null, i, true);
}
cb(null, undefined, false);
reply(null, undefined, false);
},
simpleError: function(cb) {
cb("This is an error, man!", undefined, false);
simpleError: function(reply) {
reply("This is an error, man!", undefined, false);
},
objectError: function(cb) {
cb(new Error("This is an error object, man!"), undefined, false);
objectError: function(reply) {
reply(new Error("This is an error object, man!"), undefined, false);
},
streamError: function(cb) {
cb("This is a stream error, man!", undefined, true);
streamError: function(reply) {
reply("This is a stream error, man!", undefined, true);

@@ -61,3 +58,3 @@ var error = false;

try {
cb(null, "Should not happen", false);
reply(null, "Should not happen", false);
} catch(e) {

@@ -72,5 +69,5 @@ error = true;

quiet: function(cb) {
quiet: function(reply) {
setTimeout(function() {
cb(null, "Should not happen", false);
reply(null, "Should not happen", false);
}, 31 * 1000);

@@ -80,2 +77,4 @@ }

rpcServer.bind("tcp://0.0.0.0:4242");
var rpcClient = new zerorpc.Client();

@@ -82,0 +81,0 @@ rpcClient.connect("tcp://localhost:4242");