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.
- Host: GitHub
- URL: https://github.com/system233/ws-bi-rpc
- Owner: System233
- License: mit
- Created: 2022-05-24T14:08:57.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-05-24T14:57:01.000Z (about 3 years ago)
- Last Synced: 2025-02-18T07:19:03.206Z (3 months ago)
- Language: TypeScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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```