You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

运行gRPC Java示例时出现Connection refused错误:localhost/[0:0:0:0:0:0:0:1]:50051

gRPC Java 1.53.0示例客户端连接失败问题排查(Windows 10环境)

问题概述

在Windows 10系统中完成gRPC Java 1.53.0示例项目的gradle installDist构建后,运行客户端程序build\install\examples\bin\hello-world-client时,出现RPC调用失败,报错为Connection refused: no further information: localhost/[0:0:0:0:0:0:0:1]:50051。

环境信息

Microsoft Windows [Version 10.0.19045.2604]
java version "19.0.2" 2023-01-17
Java(TM) SE Runtime Environment (build 19.0.2+7-44)
Java HotSpot(TM) 64-Bit Server VM (build 19.0.2+7-44, mixed mode, sharing)
javac 19.0.2
Gradle 8.0.1

完整报错日志

C:\Users\admin\Downloads\grpc-java-1.53.0\examples>build\install\examples\bin\hello-world-client
2023年2月22日 上午11:24:41 io.grpc.examples.helloworld.HelloWorldClient greet
信息: Will try to greet world ...
2023年2月22日 上午11:24:41 io.grpc.examples.helloworld.HelloWorldClient greet
警告: RPC failed: Status{code=UNAVAILABLE, description=io exception, cause=io.grpc.netty.shaded.io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: localhost/[0:0:0:0:0:0:0:1]:50051
Caused by: java.net.ConnectException: Connection refused: no further information
        at java.base/sun.nio.ch.Net.pollConnect(Native Method)
        at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
        at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:973)
        at io.grpc.netty.shaded.io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:337)
        at io.grpc.netty.shaded.io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334)
        at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:710)
        at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658)
        at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584)
        at io.grpc.netty.shaded.io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496)
        at io.grpc.netty.shaded.io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
        at io.grpc.netty.shaded.io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
        at io.grpc.netty.shaded.io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:1589)
}

解决步骤

  • 启动gRPC服务端程序:客户端连接前必须确保服务端已启动。在相同目录下打开新的命令行窗口,运行build\install\examples\bin\hello-world-server,待服务端输出启动成功信息后,再运行客户端程序。
  • 检查端口占用情况:执行命令netstat -ano | findstr :50051,查看端口50051是否被其他进程占用。若有,可通过任务管理器结束对应进程,或修改示例代码中的端口号后重新构建。
  • 强制使用IPv4连接:报错中客户端尝试连接IPv6的localhost(::1),若系统IPv6配置异常,可修改HelloWorldClient.java中的目标地址为127.0.0.1:50051,执行gradle installDist重新构建后再运行客户端。

内容的提问来源于stack exchange,提问作者Đỗ Như Vỹ

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.30 16:06:28