Copy it again, practicing.
/** Golang NET/RPC HTTP */package main import ("Errors" "FMT" "Log" "Net" "Net/http" "Net/rpc" "Time") var p = fmt. Println type Args struct {A, B int} type quotient struct {Quo, Rem int} type Arith int func (this *arith) multip Ly (args *args, reply *int) error {*reply = args. A * args. B return Nil} func (this *arith) Divide (args *args, quo *quotient) error {if args. B = = 0 {return errors. New ("Divide by Zero")} quo. Quo = args. A/args. B Quo. Rem = args. A% args. B return Nil} func main () {//server Arith: = new (Arith) RPC. Register (Arith) RPC. Handlehttp ()//defaultrpcpath l, E: = Net. Listen ("TCP", ": 1234") if E!= nil {log. Fatal ("Listen error:", e)} go http. Serve (l, Nil) time. Sleep (2 * time. Second)//client//Synchronous call client, err: = RPC. Dialhttp ("TCP", "127.0.0.1:1234") if Err!= nil {log. Fatal ("Dialing:", Err)} args: = &args{7, 8} var reply int err = client. Call ("Arith.multiply", args, &reply) if Err!= nIl {log. Fatal ("Arith error:", err)} FMT. Printf ("Arith:%d*%d=%d\n", args.) A, args. B, Reply)//Asynchronous Call Quotient: = new (quotient) Divcall: = client. Go ("Arith.divide", args, quotient, nil) Replycall: = <-divcall.done//would be equal to Divcall//check errors, Prin
T, etc. 7 except 8 quotient 0 7 p (replycall.reply) time. Sleep (1 * time.
Hour)//http://127.0.0.1:1234/debug/rpc}