https://github.com/notedit/bsonrpc
a rpc from http://code.google.com/p/vitess/
https://github.com/notedit/bsonrpc
Last synced: 5 months ago
JSON representation
a rpc from http://code.google.com/p/vitess/
- Host: GitHub
- URL: https://github.com/notedit/bsonrpc
- Owner: notedit
- Created: 2012-03-04T17:39:16.000Z (about 14 years ago)
- Default Branch: master
- Last Pushed: 2012-03-05T13:14:20.000Z (about 14 years ago)
- Last Synced: 2025-02-04T15:44:05.534Z (over 1 year ago)
- Homepage:
- Size: 102 KB
- Stars: 5
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# bsonrpc
a rpc from http://code.google.com/p/vitess/
# go rpc server:
```go
package main
import (
"net/rpc"
"bsonrpc"
)
type Args struct {
A, B int
}
type Reply struct {
C int
}
type Arith int
func (t *Arith) Add(args *Args, reply *Reply) error {
reply.C = args.A + args.B
return nil
}
func (t *Arith) Mul(args *Args, reply *Reply) error {
reply.C = args.A * args.B
return nil
}
func (t *Arith) NError(args *Args, reply *Reply) error {
return errors.New("normalerror")
}
func main(){
rpc.Register(new(Arith))
bsonrpc.ListenAndServe("localhost:9999")
}
```
# python rpc client
```python
import bsonrpc
addr = 'localhost:9999'
uri = 'http://%s/_bson_rpc_' % addr
client = bsonrpc.BsonRpcClient(uri,5.0)
reply = client.call('Arith.Add',{'A':7,'B':8})
print reply.sequence_id,reply.reply
reply = client.call('Arith.Mul',{'A':4,'B':8})
print reply.sequence_id,reply.reply
```