duanchi4184 2018-02-08 07:11
浏览 525
已采纳

如何正确设置gRPC客户端-服务器

I have a gRPC client and a server, when I run them they seem to be running fine, but when I try to dial a server with a client I get an error:

"Error": {
    "code": 14,
    "message": "all SubConns are in TransientFailure"
},

No idea what is it. I tried to find a solution with google, no success there.

Any ideas? Here is my server code:

lis, err := net.Listen("tcp", fmt.Sprintf("%s:%d", cfg.Host, cfg.Port))
if err != nil {
    logger.Critical(ctx, "failed to listen: %v", err)
} else {
    logger.Info(ctx, "[userserver] running at %s:%d", cfg.Host, cfg.Port)
}

grpcServer := grpc.NewServer()
userServer := userserver.New()
pb.RegisterDomainServer(grpcServer, userServer)
rpcErr := grpcServer.Serve(lis)

if rpcErr != nil {
    logger.Critical(ctx, "failed to serve: %v", rpcErr)
}

btw the server here shows log:

2018/02/08 07:03:37.603287 INFO: [userserver] running at localhost:3001

and client:

conn, err := grpc.Dial(c.serverAddr, grpc.WithInsecure())
if err != nil {
    return err
}
defer conn.Close()

client := pb.NewDomainClient(conn)
_, err = client.Dispatch(ctx, &pb.Command{
    Name:    command,
    Payload: payload,
})

and this is port buff

service Domain {
  rpc Dispatch(Command) returns (Response);
}

message Command {
  string name = 1;
  bytes payload = 2;
}

message Response {}
  • 写回答

2条回答 默认 最新

  • douba6365 2018-02-08 15:33
    关注

    Is the server listening to that port?

    // Most linux 
    lsof -i :3001
    
    // OSX
    lsof -iTCP -sTCP:LISTEN -P
    

    Are you connecting the client to the right address?

    c.serverAddr should be "127.0.0.1:3001"

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Cesm如何关闭不用的模块呢
  • ¥15 vue2两层数据导出为excle
  • ¥15 有人能帮我做一下这个项目吗
  • ¥15 网络上传速率比下载速率高
  • ¥15 (标签-游戏|关键词-网页游戏)
  • ¥15 这个咋搞🥹可能需要手把手教
  • ¥15 RFID标签芯片ROCKY100配置成SPI主机问题
  • ¥15 接口和关键字的问题,多选
  • ¥15 yolov5s模型下载就卡住,没有运行结果
  • ¥20 androidstudio工具问题