RPC Client Server with GO
Guys, how do I get two integer values from the client by the terminal in this code, in arg A and B ? I need to make an account on the server and return it, but I don't understand go
SERVER
package main
import (
"log"
"net"
"net/http"
"net/rpc"
)
type Args struct{A,B int}
type BannerMessageServer string
func (t *BannerMessageServer) GetBannerMessage(args *Args, reply *string) error {
*reply = "Sever OK"
return nil
}
func main() {
banner := new(BannerMessageServer)
rpc.Register(banner)
rpc.HandleHTTP()
port := ":1122"
listener, err := net.Listen("tcp", port)
if err != nil {
log.Fatal("listen error: ", err)
}
http.Serve(listener, nil)
}
CLIENT
package main
import (
"log"
"net/rpc"
)
type Args struct{
A, B int
}
func main() {
hostname := "localhost"
port := ":1122"
var reply string
args := Args{A,B}
client, err := rpc.DialHTTP("tcp", hostname+port)
if err != nil {
log.Fatal("dialing: ", err)
}
err = client.Call("BannerMessageServer.GetBannerMessage", args, &reply)
if err != nil {
log.Fatal("error", err)
}
// log the result
log.Printf("%s\n", reply)
}
It's an rpc client server, I want to receive two values to do mathematical calculation and return
Can anyone help? need more details, just ask