This action will force synchronization from feimat/rpc for nodejs, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
nodejs实现的rpc(基于koa实现),以网页聊天室为示例。 支持所有pc与手机浏览器 支持所有app内部webview 支持自动重连 支持心跳处理 支持双向rpc与单向通信 支持协程功能。欢迎使用与反馈bug。技术交流qq群:339711102 项目地址 https://git.oschina.net/feimat/qiyi
使用教程: git clone https://git.oschina.net/feimat/qiyi.git cd qiyi/ npm install 然后 node index.js
网页 http://localhost:3001/ 即可访问聊天。
发送rpc请求(这里演示客户端发送,服务器端发送参考示例):
var rpc_client = new rpcClient('http://‘+host);
var data = "hello";
rpc_client.emit('chat', data,{
"success": function(response) {
console.log(response)
},
"timeout_time": 4000,
"timeout_cb": function() {
},
"error": function() {
}
});
接受rpc请求(这里演示服务器端接收,客户端接受参考示例):
// next:沿用koa个人感觉没必要暴露
// ctx: 对端socket上下文信息
// message: 接收到的消息
// cb: 回调函数 cb(data) 表示返回data给发送端
app.io.route('chat', function* (next, ctx, message,cb) {
cb("server recive "+message+" and start send to other people ");
var send_suc_num = 0; // 成功收到消息的聊天成员
for (var socket in all_sockets) {
// 服务器端向客户端发送rpc
app.emit(socket, 'chat', message,{
"success": function(response) {
console.log("suc recive num:"+send_suc_num);
},
"timeout_time": 4000,
"timeout_cb": function() {
},
"error": function() {
}
});
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。