服务端代码:服务端接收student分数,返回Performance成绩评级和评语。package mainimport ( "log" "net" "net/http" "net/rpc")type Student struct { Name string Score float64}type Performance struct { Name string Grade rune Comment string}type RpcServer intfunc (r *RpcServer) SetGrade(s *Student, p *Performance) error { p.Name = s.Name if s.Score >= 80 { p.Grade = 'A' p.Comment = "Very good!" } else if s.Score >= 60 && s.Score p.Grade = 'B' p.Comment = "Good!" } else { p.Grade = 'C' p.Comment = "Bad!" } return nil}func main() { rpcser := new(RpcServer) rpc.Register(rpcser) rpc.HandleHTTP() listen, err := net.Listen("tcp", "172.16.1.28:1234") if err != nil { log.Fatal("Server starting error:", err) } http.Serve(listen, nil)}客户端:调用服务端方法,得到该student的成绩评级和评语。package mainimport ( "fmt" "log" "net/rpc")type Student struct { Name string Score float64}type Performance struct { Name string Grade rune Comment string}func main() { var performance Performance client, err := rpc.DialHTTP("tcp", "172.16.1.28:1234") if err != nil { log.Fatal("dialing:", err) } stu := &Student{ Name: "Tom", Score: 90, } err = client.Call("RpcServer.SetGrade", stu, &performance) if err != nil { log.Fatal("RpcServer error:", err) } fmt.Printf("%s:Grade:%c,Comment:%s\n", performance.Name, performance.Grade, performance.Comment)} 09-06 08:45