Dart 颤振gRPC错误-操作系统错误:连接被拒绝

Dart 颤振gRPC错误-操作系统错误:连接被拒绝,dart,flutter,protocol-buffers,grpc,Dart,Flutter,Protocol Buffers,Grpc,我使用protobuf和gRPC在颤振应用程序和python服务器(颤振中的客户端和python中的服务器)之间交换信息。服务器运行在0.0.0.0上,客户端正在使用服务器计算机的IP地址 import 'dart:async'; import 'User.pbgrpc.dart'; import 'User.pb.dart'; import 'package:grpc/grpc.dart'; Future<Null> main() async { final channel

我使用protobuf和gRPC在颤振应用程序和python服务器(颤振中的客户端和python中的服务器)之间交换信息。服务器运行在0.0.0.0上,客户端正在使用服务器计算机的IP地址

import 'dart:async';
import 'User.pbgrpc.dart';
import 'User.pb.dart';
import 'package:grpc/grpc.dart';

Future<Null> main() async {
  final channel = new ClientChannel('IP_ADDRESS',
      port: 50051,
      options: const ChannelOptions(
          credentials: const ChannelCredentials.insecure()));
  final stub = new StorageClient(channel);

  Test input = new Test();
  input.id = 1;
  try {
    var response = await stub.getPerson(input);
    print('Greeter client received: ${response}');
  } catch (e) {
    print('Caught error: $e');
  }
  await channel.shutdown();
}
我得到:

I/flutter (18824): Caught error: gRPC Error (14, Error connecting: SocketException: OS Error: No route to host, errno = 111, address = localhost, port = 45638)

更新:当我使用模拟器运行应用程序时,它正在工作。所以这是一个只有在使用真实设备时才会发生的错误。

在我的例子中,这是一个防火墙问题。在服务器上运行
systemctl stop firewalld
解决了这个问题。

如果在同一台计算机上运行AVD(客户端)和后端,则必须将基本URL而不是“localhost/127.0.0.1”设置为“10.0.2.2”


答案在这里。

也许不是。我没有运行
firewalld
,但仍然收到此错误。
I/flutter (18824): Caught error: gRPC Error (14, Error connecting: SocketException: OS Error: No route to host, errno = 111, address = localhost, port = 45638)