Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
G
golang
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
golang
Commits
44670373
Commit
44670373
authored
Mar 18, 2010
by
Robert Griesemer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rpc documentation cleanup: remove ;'s from code in documentation
R=r CC=golang-dev
https://golang.org/cl/624042
parent
7f775183
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
18 deletions
+18
-18
server.go
src/pkg/rpc/server.go
+18
-18
No files found.
src/pkg/rpc/server.go
View file @
44670373
...
...
@@ -53,53 +53,53 @@
type Arith int
func (t *Arith) Multiply(args *Args, reply *Reply) os.Error {
reply.C = args.A * args.B
;
reply.C = args.A * args.B
return nil
}
func (t *Arith) Divide(args *Args, reply *Reply) os.Error {
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
}
The server calls (for HTTP service):
arith := new(Arith)
;
rpc.Register(arith)
;
rpc.HandleHTTP()
;
l, e := net.Listen("tcp", ":1234")
;
arith := new(Arith)
rpc.Register(arith)
rpc.HandleHTTP()
l, e := net.Listen("tcp", ":1234")
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
"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 {
log.Exit("dialing:", err)
;
log.Exit("dialing:", err)
}
Then it can make a remote call:
// Synchronous call
args := &server.Args{7,8}
;
reply := new(server.Reply)
;
err = client.Call("Arith.Multiply", args, reply)
;
args := &server.Args{7,8}
reply := new(server.Reply)
err = client.Call("Arith.Multiply", args, reply)
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
// Asynchronous call
divCall := client.Go("Arith.Divide", args, reply, nil)
;
replyCall := <-divCall.Done
;
// will be equal to divCall
divCall := client.Go("Arith.Divide", args, reply, nil)
replyCall := <-divCall.Done // will be equal to divCall
// check errors, print, etc.
A server implementation will often provide a simple, type-safe wrapper for the
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment