一个用于Node应用的简单、快速RPC框架:kamote

jopen 10年前

kamote是一个用于Node应用的简单、快速RPC框架。

安装

$ npm install kamote --save

安装最新版本

$ npm install git+https://github.com/majimboo/kamote.git

服务器

创建一个新的服务

var kamote = require('kamote');  var server = new kamote.Server();

事件:

  • error - When an error occurs.

方法:

  • add([name, ]function) - Adds a function to be exposed over RPC.
  • listen(port[, host] - Binds the server to the specified endpoint.

完整示例:

var kamote = require('kamote');  var server = new kamote.Server();    server.add('plusOne', function(value) {      console.log(value + 1);  });    server.listen(9456);

You can also use the context style:

function plusOne(n, result) {      result(n + 1);  }    var server = new kamote.Server();  server.listen(6123);  server.def({      plusOne: plusOne  });

客户端

To create a new client:

var kamote = require('kamote');  var client = new kamote.Client();

Events:

  • error - When an error occurs.
  • connect - When the socket has connected to the server.
  • disconnect - When disconnected from the server.
  • ready - When all the remote functions has been loaded.

Methods:

  • connect(port [, host]) - Connects to the remote host:port.
  • reconnect(port [, host]) - Connects to the remote host:port and retries if unable.

Full example:

var kamote = require('kamote');  var client = new kamote.Client();    client.plusOne(100, function(result) {      console.log(result); // 101  });    client.reconnect(9456);

项目主页:http://www.open-open.com/lib/view/home/1411615071375</p> </strong>