I’m new to golang. I’m creating an RPC server. What I have working code that will add two numbers. What I need is to generate random numbers. Any help would be greatly appreciated. Thanks!
Server:
package main
import (
“net/http”
“net/rpc”
)
type Arith int
type Arguments struct {
A, B int
}
func (a *Arith) Addition(args Arguments, result *int) error {
*result = args.A + args.B
return nil
}
func main() {
arith := new(Arith)
rpc.Register(arith)
rpc.HandleHTTP()
http.ListenAndServe(":8001", nil)
}
Client:
package main
import (
“fmt”
“net/rpc”
)
type Args struct {
A, B int
}
func main() {
client, err := rpc.DialHTTP(“tcp”, “:8001”)
if err != nil {
fmt.Println(err)
}
args := Args{10, 6}
var result int
err2 := client.Call("Arith.Addition", args, &result)
if err2 != nil {
fmt.Println(err2)
}
fmt.Println(result)
}