soheilhy / cmux

Connection multiplexer for GoLang: serve different services on the same port!
Apache License 2.0
2.53k stars 197 forks source link

how to write client codeto gprc connect #80

Open lee123456780 opened 3 years ago

lee123456780 commented 3 years ago

can you give me a client demo code for gRPC ? ths

lee123456780 commented 3 years ago

MY CODE LIKE THIS conn, err := grpc.Dial("localhost:1234", grpc.WithInsecure()) if err != nil { log.Fatal(err) } defer conn.Close() ct := go_protoc.NewGreeterClient(conn) re, err1 := ct.SayHello(context.Background(), &go_protoc.HelloRequest{ Name: "hello word", }) fmt.Println(re) if err1 != nil { log.Fatal(err1) } BUT I GOT AN ERROR : rpc error: code = Unavailable desc = timed out waiting for server handshake WHAT'S WRONG?

stevenferrer commented 1 year ago

As per README, you'll have to match with writers.

grpcl := m.MatchWithWriters(cmux.HTTP2MatchHeaderFieldSendSettings("content-type", "application/grpc"))