55 lines
1.0 KiB
Go
55 lines
1.0 KiB
Go
package main
|
|
|
|
import (
|
|
rpc "github.com/special/ricochet-go/rpc"
|
|
"golang.org/x/net/context"
|
|
"google.golang.org/grpc"
|
|
"io"
|
|
"log"
|
|
)
|
|
|
|
const (
|
|
defaultAddress = "127.0.0.1:58281"
|
|
)
|
|
|
|
func main() {
|
|
conn, err := grpc.Dial(defaultAddress, grpc.WithInsecure())
|
|
if err != nil {
|
|
log.Fatalf("connection failed: %v", err)
|
|
}
|
|
defer conn.Close()
|
|
|
|
c := rpc.NewRicochetCoreClient(conn)
|
|
|
|
r, err := c.GetServerStatus(context.Background(), &rpc.ServerStatusRequest{
|
|
RpcVersion: 1,
|
|
})
|
|
if err != nil {
|
|
log.Fatalf("could not get status: %v", err)
|
|
}
|
|
log.Printf("get status result: %v", r)
|
|
|
|
stream, err := c.MonitorNetwork(context.Background(), &rpc.MonitorNetworkRequest{})
|
|
if err != nil {
|
|
log.Fatalf("could not start stream: %v", err)
|
|
}
|
|
|
|
wait := make(chan struct{})
|
|
go func() {
|
|
for {
|
|
resp, err := stream.Recv()
|
|
if err == io.EOF {
|
|
log.Printf("stream eof")
|
|
break
|
|
}
|
|
if err != nil {
|
|
log.Fatalf("stream error: %v", err)
|
|
}
|
|
log.Printf("stream says: %v", resp)
|
|
}
|
|
wait <- struct{}{}
|
|
}()
|
|
|
|
<-wait
|
|
}
|