O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How to do it...

  1. Open the console and create the folder chapter07/recipe11.
  2. Navigate to the directory.
  3. Create the jsonrpc.go file with the following content:
        package main        import (          "log"          "net"          "net/rpc"          "net/rpc/jsonrpc"        )        type Args struct {          A, B int        }        type Result int        type RpcServer struct{}        func (t RpcServer) Add(args *Args, result *Result) error {          log.Printf("Adding %d to %d\n", args.A, args.B)          *result = Result(args.A + args.B)          return nil        }         const addr = ":7070"         func main() {          go createServer(addr)          client, err := jsonrpc.Dial("tcp", addr)          if err != nil {            panic(err)          }          defer client.Close()          args := &Args{            A: 2,            B: 3,          }          var result Result          err = client.Call("RpcServer.Add", args, &result)          if err != nil { log.Fatalf("error in RpcServer", err) ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required