一個用于Node應用的簡單、快速RPC框架:kamote
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.
</ul>
add([name, ]function)
- Adds a function to be exposed over RPC.listen(port[, host]
- Binds the server to the specified endpoint.
</ul>
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.
</ul>
connect(port [, host])
- Connects to the remote host:port.reconnect(port [, host])
- Connects to the remote host:port and retries if unable.
</ul>
方法:
完整示例:
var kamote = require('kamote');
var server = new kamote.Server();
server.add('plusOne', function(value) {
console.log(value + 1);
});
server.listen(9456);</pre></code>
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
});</pre></code>
客戶端
To create a new client:
var kamote = require('kamote');
var client = new kamote.Client();
Events:
Methods:
Full example:
var kamote = require('kamote');
var client = new kamote.Client();
client.plusOne(100, function(result) {
console.log(result); // 101
});
client.reconnect(9456);</pre></code> 項目主頁:http://www.baiduhome.net/lib/view/home/1411615071375</p>
</strong>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!