Created
October 8, 2022 09:04
-
-
Save audrenbdb/4df8b78aaa43692f891fb4628daf5917 to your computer and use it in GitHub Desktop.
This file contains 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 ( | |
"context" | |
"fmt" | |
"log" | |
"time" | |
"google.golang.org/grpc" | |
"google.golang.org/grpc/credentials/insecure" | |
) | |
func main() { | |
conn, err := grpc.DialContext(context.Background(), "localhost:50051", grpc.WithTransportCredentials(insecure.NewCredentials())) | |
if err != nil { | |
log.Fatal(err) | |
} | |
defer conn.Close() | |
exp := time.After(50 * time.Second) | |
ticker := time.NewTicker(1 * time.Second) | |
for { | |
select { | |
case <-exp: | |
ticker.Stop() | |
return | |
case <-ticker.C: | |
fmt.Printf("Connection status: %s\n", conn.GetState().String()) | |
} | |
} | |
} |
This file contains 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 ( | |
"log" | |
"net" | |
"google.golang.org/grpc" | |
) | |
func main() { | |
lis, err := net.Listen("tcp", ":50051") | |
if err != nil { | |
log.Fatalf("failed to listen: %v", err) | |
} | |
s := grpc.NewServer() | |
s.Serve(lis) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment