Commit 44670373 authored by Robert Griesemer's avatar Robert Griesemer

rpc documentation cleanup: remove ;'s from code in documentation

R=r
CC=golang-dev
https://golang.org/cl/624042
parent 7f775183
...@@ -53,53 +53,53 @@ ...@@ -53,53 +53,53 @@
type Arith int type Arith int
func (t *Arith) Multiply(args *Args, reply *Reply) os.Error { func (t *Arith) Multiply(args *Args, reply *Reply) os.Error {
reply.C = args.A * args.B; reply.C = args.A * args.B
return nil return nil
} }
func (t *Arith) Divide(args *Args, reply *Reply) os.Error { func (t *Arith) Divide(args *Args, reply *Reply) os.Error {
if args.B == 0 { if args.B == 0 {
return os.ErrorString("divide by zero"); return os.ErrorString("divide by zero")
} }
reply.C = args.A / args.B; reply.C = args.A / args.B
return nil return nil
} }
The server calls (for HTTP service): The server calls (for HTTP service):
arith := new(Arith); arith := new(Arith)
rpc.Register(arith); rpc.Register(arith)
rpc.HandleHTTP(); rpc.HandleHTTP()
l, e := net.Listen("tcp", ":1234"); l, e := net.Listen("tcp", ":1234")
if e != nil { if e != nil {
log.Exit("listen error:", e); log.Exit("listen error:", e)
} }
go http.Serve(l, nil); go http.Serve(l, nil)
At this point, clients can see a service "Arith" with methods "Arith.Multiply" and At this point, clients can see a service "Arith" with methods "Arith.Multiply" and
"Arith.Divide". To invoke one, a client first dials the server: "Arith.Divide". To invoke one, a client first dials the server:
client, err := rpc.DialHTTP("tcp", serverAddress + ":1234"); client, err := rpc.DialHTTP("tcp", serverAddress + ":1234")
if err != nil { if err != nil {
log.Exit("dialing:", err); log.Exit("dialing:", err)
} }
Then it can make a remote call: Then it can make a remote call:
// Synchronous call // Synchronous call
args := &server.Args{7,8}; args := &server.Args{7,8}
reply := new(server.Reply); reply := new(server.Reply)
err = client.Call("Arith.Multiply", args, reply); err = client.Call("Arith.Multiply", args, reply)
if err != nil { if err != nil {
log.Exit("arith error:", err); log.Exit("arith error:", err)
} }
fmt.Printf("Arith: %d*%d=%d", args.A, args.B, reply.C); fmt.Printf("Arith: %d*%d=%d", args.A, args.B, reply.C)
or or
// Asynchronous call // Asynchronous call
divCall := client.Go("Arith.Divide", args, reply, nil); divCall := client.Go("Arith.Divide", args, reply, nil)
replyCall := <-divCall.Done; // will be equal to divCall replyCall := <-divCall.Done // will be equal to divCall
// check errors, print, etc. // check errors, print, etc.
A server implementation will often provide a simple, type-safe wrapper for the A server implementation will often provide a simple, type-safe wrapper for the
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment