tranel-socket

0.3.0 • Public • Published

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.

Readme

Keywords

Package Sidebar

Install

npm i tranel-socket

Weekly Downloads

1

Version

0.3.0

License

MIT

Unpacked Size

25.1 kB

Total Files

9

Last publish

Collaborators

  • etoah