package rpcsupport
import ( "log" "net" "net/rpc" "net/rpc/jsonrpc" )
func ServeRpc(host string, service interface{}) error { err := rpc.Register(service) if err != nil { return err } listener, err := net.Listen("tcp", host) if err != nil { return err } for { conn, err := listener.Accept() if err != nil { log.Printf("accept error") } go jsonrpc.ServeConn(conn) } return nil }
func NewClient(host string) (*rpc.Client, error) { conn, err := net.Dial("tcp", host) if err != nil { return nil, err } client := jsonrpc.NewClient(conn) return client, nil }