-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (41 loc) · 926 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package main
import (
"rpc"
"time"
)
type Args struct{ Num1, Num2 int }
type Rabbit struct{}
func (r *Rabbit) Add(args Args, re *int) error {
*re = args.Num1 + args.Num2
return nil
}
func (r *Rabbit) Minus(args Args, re *int) error {
*re = args.Num1 - args.Num2
return nil
}
func main() {
addr := make(chan string)
server := rpc.Server{}
rabbit := &Rabbit{}
server.Register(rabbit)
s := make([]*rpc.Single, 0)
s = append(s, &rpc.Single{
Address: "[::]",
Port: 8080,
Max_retry_times: 10,
})
server.Discover(s)
go server.StartServer(addr)
client := rpc.NewClient(<-addr, 1*time.Second)
defer client.Conn.Close()
go client.Receive()
for i := 0; i < 5; i++ {
call := new(rpc.Call)
call.Seq = uint64(i)
call.ServiceMethod = "Rabbit.Add"
call.Arguments = &Args{1, i}
client.RegisterCall(call)
time.Sleep(800 * time.Millisecond)
}
time.Sleep(3 * time.Second)
}