Created
November 18, 2016 08:41
-
-
Save ijingo/1347c5abf314a8c3a725bafa86c79a4b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"log" | |
"net/rpc" | |
"shared" | |
) | |
type Arith struct { | |
client *rpc.Client | |
} | |
func (t *Arith) Multiply(a, b int) int { | |
args := &shared.Args{a, b} | |
var reply int | |
err := t.client.Call("Arith.Multiply", args, &reply) | |
if err != nil { | |
log.Fatal("arith error, ", err) | |
} | |
return reply | |
} | |
func (t *Arith) Divide(a, b int) shared.Quotient { | |
args := &shared.Args{a, b} | |
var reply shared.Quotient | |
err := t.client.Call("Arith.Divide", args, &reply) | |
if err != nil { | |
log.Fatal("arith error, ", err) | |
} | |
return reply | |
} | |
func main() { | |
client, err := rpc.DialHTTP("tcp", "localhost:1234") | |
if err != nil { | |
log.Fatal("dial error, ", err) | |
} | |
arith := Arith{client} | |
fmt.Println(arith.Multiply(5, 6)) | |
fmt.Println(arith.Divide(500, 9)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment