【问题标题】:"transport: Error while dialing dial tcp 127.0.0.1:9001: connect: connection refused"“传输:拨打拨号 TCP 127.0.0.1:9001 时出错:连接:连接被拒绝”
【发布时间】:2021-07-31 01:55:31
【问题描述】:

在 golang 中,我正在尝试实现 GRPC,但出现此错误。其他一切看起来都很好。

这里是代码sn-p。

type EventServiceClient struct {
Client proto.EventServiceClient
Conn   *grpc.ClientConn
}

func InitEventServiceClient(addr int) (msc EventServiceClient, err error) {

conn, err := grpc.Dial("localhost:9001", grpc.WithInsecure())
if err != nil {
    return
}

client := proto.NewEventServiceClient(conn)
msc = EventServiceClient{
    Conn:   conn,
    Client: client,
}

return
}

错误-

rpc 错误:code = Unavailable desc = connection error: desc = "transport: Error while dialing dial tcp 127.0.0.1:9001: connect: connection denied"

【问题讨论】:

  • 确保你能ping通主机,防火墙也没有阻塞
  • 无法 ping 主机,但防火墙看起来不错,没有任何问题。
  • 请提供有关您尝试连接的 gRPC 服务器的更多信息(例如,您如何验证它正在运行,操作系统/环境信息(docker?),您可以使用gRPCurl 或类似的工具)。

标签: go grpc


【解决方案1】:

localhost 可能是 ip6 (::1) - 尝试 127.0.0.1:9001 或 0.0.0.0:9001 获取所有 ip

【讨论】:

  • 不,所有 ip 的 localhost 都是 ip4
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-02-21
  • 2019-12-12
  • 2018-12-26
  • 2019-12-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多