Skip to content

Instantly share code, notes, and snippets.

@ijingo
Created November 18, 2016 08:43
Show Gist options
  • Save ijingo/1f2307181c1a6e8d43af2dd3c42f673b to your computer and use it in GitHub Desktop.
Save ijingo/1f2307181c1a6e8d43af2dd3c42f673b to your computer and use it in GitHub Desktop.
package main
import (
"errors"
"log"
"net"
"net/rpc"
"shared"
)
type Arith int
func (t *Arith) Multiply(args *shared.Args, reply *int) error {
*reply = args.A * args.B
return nil
}
func (t *Arith) Divide(args *shared.Args, reply *shared.Quotient) error {
if args.B == 0 {
return errors.New("Divided by zero")
}
reply.Quo = args.A / args.B
reply.Rem = args.A % args.B
return nil
}
func main() {
arith := new(Arith)
server := rpc.NewServer()
server.Register(shared.Arith(arith))
l, e := net.Listen("tcp", "localhost:1234")
if e != nil {
log.Fatal("listen error", e)
}
server.Accept(l)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment