https://github.com/jnordberg/wsrpc
node.js/browser protobuf rpc over binary websockets
https://github.com/jnordberg/wsrpc
browser nodejs rpc websockets
Last synced: about 1 month ago
JSON representation
node.js/browser protobuf rpc over binary websockets
- Host: GitHub
- URL: https://github.com/jnordberg/wsrpc
- Owner: jnordberg
- License: other
- Created: 2017-04-28T15:12:57.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2022-12-30T18:55:57.000Z (over 2 years ago)
- Last Synced: 2025-04-11T19:08:00.816Z (about 1 month ago)
- Topics: browser, nodejs, rpc, websockets
- Language: TypeScript
- Homepage: https://jnordberg.github.io/wsrpc/
- Size: 2.3 MB
- Stars: 104
- Watchers: 7
- Forks: 11
- Open Issues: 16
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# [wsrpc](https://github.com/jnordberg/wsrpc) [](https://travis-ci.org/jnordberg/wsrpc) [](https://coveralls.io/github/jnordberg/wsrpc?branch=master) [](https://www.npmjs.com/package/wsrpc) 
node.js/browser protobuf rpc over binary websockets.
* **[Demo](https://johan-nordberg.com/wspainter)** ([source](https://github.com/jnordberg/wsrpc/tree/master/examples/painter))
* [Documentation](https://jnordberg.github.io/wsrpc/)
* [Issues](https://github.com/jnordberg/wsrpc/issues)---
Minimal example
---------------my-service.proto
```protobuf
service MyService {
rpc SayHello (HelloRequest) returns (HelloResponse) {}
}message HelloRequest {
required string name = 1;
}message HelloResponse {
required string text = 1;
}
```server.js
```typescript
const wsrpc = require('wsrpc')
const protobuf = require('protobufjs')const proto = protobuf.loadSync('my-service.proto')
const server = new wsrpc.Server(proto.lookupService('MyService'), { port: 4242 })
server.implement('sayHello', async (request) => {
return {text: `Hello ${ request.name }!`}
})
```client.js
```typescript
const wsrpc = require('wsrpc')
const protobuf = require('protobufjs')const proto = protobuf.loadSync('my-service.proto')
const client = new wsrpc.Client('ws://localhost:4242', proto.lookupService('MyService'))
const response = await client.service.sayHello({name: 'world'})
console.log(response) // Hello world!
```