type MyRPCServer struct {} func (s *MyRPCServer) GetInfo(args *Args, reply *Reply) error { // do some operation and populate reply struct *reply = // some operation result return nil } func main() { server := rpc.NewServer() err := server.Register(&MyRPCServer{}) if err != nil { log.Fatal("Error registering RPC server:", err) } conn, err := net.Listen("tcp", ":8080") if err != nil { log.Fatal("Error starting listener:", err) } for { clientConn, err := conn.Accept() if err != nil { log.Fatal("Error accepting connection:", err) } go server.ServeConn(clientConn) } }
type MyRPCServer struct {} func (s *MyRPCServer) GetInfo(args *Args, reply *Reply) error { // do some operation and populate reply struct *reply = // some operation result return nil } func main() { client, err := rpc.Dial("tcp", "localhost:8080") if err != nil { log.Fatal("Error connecting to server:", err) } args := &Args{// some data} var reply Reply err = client.Call("MyRPCServer.GetInfo", args, &reply) if err != nil { log.Fatal("Error calling RPC method:", err) } // use reply data }In this example, we define an RPC client which connects to an RPC server at "localhost:8080". We then define an `Args` struct and a `Reply` struct which we will populate with data from the server's `GetInfo` method by calling `client.Call()`. We can then use the data in the `Reply` struct as necessary. These examples use the `net/rpc` package in Go.