ubuntu - 调用 tcp 127.0.0.1 :9091: connect: connection refused

标签 ubuntu protocol-buffers grpc grpc-java protobuf-java

我正在使用 gRPC 应用程序并构建一个简单的应用程序。文件下方。

syntax = "proto3";
option java_multiple_files = true;
package com.grpc;

message HelloRequest {
    string firstName = 1;
    string lastname = 2;
}
message HelloResponse {
    string greeting = 1;
}
service HelloService {
    rpc hello(HelloRequest) returns (HelloResponse);
}
它正常生成文件
User.java -> generated from protoc compiler
userGrpc.java -> generated from protoc compiler
GRPCService.java
package GRPCService;

import java.io.IOException;

import io.grpc.Server;
import io.grpc.ServerBuilder;
import user.UserService;

public class GPRCService {
    public static void main(String[] args) throws IOException, InterruptedException {
        Server server = ServerBuilder.forPort(9091).addService(new UserService()).build();  
        server.start();
        System.out.println("Server started at " +  server.getPort());
        server.awaitTermination();
    }
}
system.out.println 显示服务器正在运行;
Server started at 9091
然后我在 ubuntu 18.04 的 9091 端口上打开了 TCP 的防火墙规则
sudo ufw allow from any to any port 9091 proto tcp
结果:
java      28277    ubuntu   49u  IPv6   478307      0t0  TCP *:9091 (LISTEN)
我什至可以从终端 curl
* Rebuilt URL to: http://localhost:9091/
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 9091 (#0)
> GET / HTTP/1.1
> Host: localhost:9091
> User-Agent: curl/7.58.0
> Accept: */*
> 
Warning: Binary output can mess up your terminal. Use "--output -" to tell 
Warning: curl to output it to your terminal anyway, or consider "--output 
Warning: <FILE>" to save to a file.
* Failed writing body (0 != 40)
* stopped the pause stream!
* Closing connection 0
curl 命令
   curl -v http://localhost:9091
但是当从 gui 客户端执行时
https://github.com/gusaul/grpcox
我收到连接被拒绝。
dial tcp 127.0.0.1:9091: connect: connection refused
Error from client
我没有使用任何 VPN 或代理,GUI 应用程序实际上是在容器内运行。
docker run -p 6969:6969 -v {ABSOLUTE_PATH_TO_LOG}/log:/log -d gusaul/grpcox
如果有人可以请帮助我。
谢谢堆栈!

最佳答案

如果您正在运行 grpcox作为 docker 容器,您需要为容器提供主机网络访问权限(最简单),以便它可以访问在主机 (!) 端口 9901 上运行的服务器即localhost:9901 ,或者提供一个DNS地址,它可以解析你的主机地址,即your-host:9901 .
对于主机网络访问,运行容器...

docker run --net=host ... gusaul/grpcox

关于ubuntu - 调用 tcp 127.0.0.1 :9091: connect: connection refused,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64139243/

相关文章:

linux - clock_gettime() 是否适合亚微秒计时?

ruby-on-rails - 无法加载此类文件 -- 套接字 (LoadError)

ios - 可达性和国际漫游

c++ - 使用 GZIP 压缩的 Protobuf

c# - .net Core Grpc 客户端无法调用 Greeter 服务

.net-core - 如何在 dotnet 核心的树莓派中部署示例 GRPC [客户端-服务器] 解决方案

java - 我可以在 Ubuntu 14.04 上开发 Java Web 应用程序并使用我的 Apache 服务器查看它们吗?

opencv - 如何在 ubuntu 18.04 中正确配置 g++ 与 opencv 的链接?

c++ - 在同一个 C++ 项目中链接两个不同版本的 protobuf 库

c++ - gRPC:长时间运行的流式传输的最佳实践是什么?