-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
46 lines (37 loc) · 764 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
package main
import (
"context"
"fmt"
pb "github.com/JaimeRC/grpc-golang/server_streaming/proto"
"google.golang.org/grpc"
"io"
"log"
)
const (
address = "localhost:50052"
)
func main() {
conn, err := grpc.Dial(address, grpc.WithInsecure())
if err != nil {
log.Fatalf("failed to connect: %v", err)
}
defer conn.Close()
c := pb.NewCountdownClient(conn)
// timer to start countdown for 10 sec
time := int32(10)
// call Start Service
stream, err := c.Start(context.Background(), &pb.CountdownRequest{Timer: time})
if err != nil {
log.Fatalf("failed to start timer: %v", err)
}
for {
msg, err := stream.Recv()
if err == io.EOF {
break
}
if err != nil {
log.Fatalf("stream read failed: %v", err)
}
fmt.Println(msg)
}
}