Options
All
  • Public
  • Public/Protected
  • All
Menu

Namespace TinyRpc

基于tinyWs的简易rpc实现

description


发送消息结构:

{
     id: "消息id",
     method: "消息名",
     params: "消息参数"
}

返回消息结构:

{
     id:"消息id",
     result:"方法结果"
}
example

创建server

var server = TinyRpcServer.create({ port: 9191 });
server.registerMethod("add", (data: any[]) => {
    return data[0] + data[1];
})
example

创建 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);
        })
})

Index

Variables

Variables

Const Client

Client: TinyRpcClient = TinyRpcClient

Const Server

Server: TinyRpcServer = TinyRpcServer

Generated using TypeDoc