基于tinyWs的简易rpc实现
发送消息结构:
{ id: "消息id", method: "消息名", params: "消息参数" }
返回消息结构:
{ id:"消息id", result:"方法结果" }
创建server
var server = TinyRpcServer.create({ port: 9191 }); server.registerMethod("add", (data: any[]) => { return data[0] + data[1]; })
创建 client
let ins: TinyRpcClient =new TinyRpcClient("ws://localhost:3030") as any; ins.on("connect", () => { //调用远程方法 ins.callMethod("add", [1, 2]) .then(result => { console.log("result equal 3", result); }) })
Generated using TypeDoc
基于tinyWs的简易rpc实现
发送消息结构:
{ id: "消息id", method: "消息名", params: "消息参数" }
返回消息结构:
{ id:"消息id", result:"方法结果" }
创建server
var server = TinyRpcServer.create({ port: 9191 }); server.registerMethod("add", (data: any[]) => { return data[0] + data[1]; })
创建 client
let ins: TinyRpcClient =new TinyRpcClient("ws://localhost:3030") as any; ins.on("connect", () => { //调用远程方法 ins.callMethod("add", [1, 2]) .then(result => { console.log("result equal 3", result); }) })