Skip to content

hyhkjiy/rpcx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

rpcx client for python

what is rpcx?

please to see rpcx.site or github!

example

service

package main

import (
	"context"
	"flag"

	"github.com/smallnest/rpcx/server"
)

var (
	addr = flag.String("addr", "localhost:8972", "127.0.0.1")
)

type Arith struct{}

type Args struct {
	A int
	B int
}

type Reply struct {
	C int
}


// the second parameter is not a pointer
func (t *Arith) Mul(ctx context.Context, args *Args, reply *Reply) error {
	reply.C = args.A * args.B
	return nil
}

func main() {
	flag.Parse()

	s := server.NewServer()
	s.Register(new(Arith), "")
	s.Serve("tcp", *addr)
}

client

from rpcx import Client
client = Client('localhost', 8972)
response = client.call('Arith', 'Mul', dict(A=2, B=3))
print(response.success)
if response.success:
    print(response.payload)
else:
    print(response.error)

contact