tranel-socket
v0.3.0
Published
RPC like function invoke by socket
Downloads
11
Readme
TranelSocket
像同一进程内一样的API去跨进程调用API
Usage
const api = { //需要代理的api
getData() {
return new Promise(rs => setTimeout(() => rs({ ret: 200 }), 50));
},
serverInfo: {
msg: "message from server",
pid: process.pid
}
}
const server = new TranelSocket();
const p = server.createServer({ port: 60000, proxyObject: api }); // 创建socket服务
// -------- client -----------
const client = new TranelSocket();
const p = client.proxy({ port: 60000, hostname: "127.0.0.1"});
client.socketChannel.addEventListener("ready", async () => {
console.log(await p.getData()); // print { ret: 200 }
console.log(await p(p.serverInfo)); // print { msg: 'message from server', pid: 66801 }
})
所有代码, 请查看examples.