Created
November 18, 2016 08:43
-
-
Save ijingo/1f2307181c1a6e8d43af2dd3c42f673b 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 ( | |
"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