package main

import (
	"fmt"
	"net/rpc"
	"os"
	"trpc/config"
)

func main() {
	client, errDial := rpc.Dial("tcp", config.Socket)
	if errDial != nil {
		fmt.Printf("RPC dial: %s.\n", errDial)
		os.Exit(1)
	}

	args := config.Args{
		A: 2,
		B: 4,
	}

	// Synchronous calls

	var reply int
	errMu := client.Call("Logic.Multiply", args, &reply)
	if errMu != nil {
		fmt.Printf("RPC call to multiply: %s.\n", errMu)
		os.Exit(2)
	}

	fmt.Printf("Arguments: %d, %d. Reply: %d\n", args.A, args.B, reply)

	var resp config.Reply
	errDiv := client.Call("Logic.Divide", args, &resp)
	if errDiv != nil {
		fmt.Printf("RPC call to divide: %s.\n", errDiv)
		os.Exit(3)
	}

	fmt.Printf("Arguments: %d, %d. Reply: %.2f\n", args.A, args.B, resp.Resp)
}
