0.5.30 • Published 16 days ago

@cloudpss/ubrpc v0.5.30

Weekly downloads
-
License
MIT
Repository
-
Last release
16 days ago

@cloudpss/ubrpc

Rpc server/client build on websocket and ubjson.

Introduction

本模块是基于 websocket 和 ubjson 的 rpc 服务端/客户端模块。使用 websocket 作为底层通信协议,使用 ubjson 作为数据序列化协议。在建立连接后,支持通过 websocket 实现双向调用。

Usage

作为 WebSocket 服务端

import { WebSocketServer } from 'ws';
import { RpcServer } from '@cloudpss/ubrpc';

const rpc = new RpcServer(
  {
    hello(name) {
      return `Hello, ${name}`;
    },
  },
  (meta) => {
    // 校验客户端信息,拒绝连接时抛出异常
    // 返回服务端信息供客户端验证
    return {};
  },
);

const server = new WebSocketServer({
  host: 'localhost',
  port: 8090,
  path: '/',
});
server.on('connection', async (socket) => {
  try {
    await rpc.connect(socket);
  } catch (ex) {
    console.log(ex);
  }
});

作为 WebSocket 客户端

import { RpcClientSocket } from '@cloudpss/ubrpc';

const rpc = new RpcClientSocket('ws://localhost:8090');
const result = await rpc.call('hello', 'world');
console.log(result);
0.5.30

16 days ago

0.5.29

1 month ago

0.5.28

2 months ago

0.5.26

2 months ago

0.5.25

2 months ago

0.5.24

2 months ago

0.5.23

2 months ago

0.5.22

2 months ago

0.5.21

2 months ago

0.5.18

2 months ago

0.5.19

2 months ago

0.5.20

2 months ago

0.5.17

2 months ago

0.5.16

4 months ago

0.5.14

4 months ago

0.5.15

4 months ago

0.5.13

4 months ago

0.5.12

4 months ago

0.5.11

5 months ago

0.5.10

5 months ago

0.5.8

5 months ago

0.5.9

5 months ago

0.4.28

10 months ago

0.4.29

10 months ago

0.4.27

10 months ago

0.4.31

9 months ago

0.4.32

9 months ago

0.4.30

9 months ago

0.4.35

8 months ago

0.4.33

8 months ago

0.4.34

8 months ago

0.5.3

6 months ago

0.5.6

6 months ago

0.5.0

6 months ago

0.5.2

6 months ago

0.5.1

6 months ago

0.4.26

11 months ago

0.4.24

11 months ago

0.4.25

11 months ago

0.4.20

12 months ago

0.4.21

12 months ago

0.4.22

12 months ago

0.4.23

12 months ago

0.4.19

12 months ago

0.4.17

1 year ago

0.4.18

1 year ago

0.4.15

1 year ago

0.4.16

1 year ago

0.4.13

1 year ago

0.4.14

1 year ago

0.4.12

1 year ago

0.4.11

1 year ago

0.4.10

1 year ago