An open API service indexing awesome lists of open source software.

https://github.com/system233/ws-bi-rpc

Bidirectional RPC based on WebSocket.
https://github.com/system233/ws-bi-rpc

Last synced: 3 months ago
JSON representation

Bidirectional RPC based on WebSocket.

Awesome Lists containing this project

README

        

# WS-BI-RPC

Bidirectional RPC based on WebSocket.

## Easy to use
```ts
import { WebSocketServer,WebSocket ,WebSocketRPC } from "..";

class ServerHander {
say(message: string) {
console.log('message from client:', message)
}
}
class ClientHander {
test(message: string) {
console.log('message from server :', message)
}
}
const server = new WebSocketServer({ host: 'localhost', port: 8899 });
server.on('connection', async (socket) => {
const rpc = new WebSocketRPC(socket, new ServerHander);
await rpc.call('test', 'hello');
});

const ws = new WebSocket('ws://localhost:8899');

ws.on('open', async () => {
const client = new WebSocketRPC(ws, new ClientHander);
await client.call('say', 'say message');
})

// message from server : hello
// message from client: say message

```