GRPC, dart lang, How to detect failure connection, succesfull connection, lost connection from the server

104 Views Asked by At

Hi I wondering how to detect connection from the server. How to solve it. As far as i know channel is an abstraction which managing services ? Do i understand it right? So I can be able to ask channel about connection to server exist. I am trying but I can't see method which returns Connection State to the server. I would think this should be implemented into the grpc library. But I can't see or I am blindness or I don' understand idea of grpc protocol. Eventually how to implement this functionality ? My example code:

import 'package:grpc/grpc.dart';

class GrpcManager {
  late ClientChannel channel;
  //late MetadaztaClient stub;
  Future<void> connect(List<String> args) async {
    channel = ClientChannel(
      '127.0.0.1',
      port: 8080,
      options: const ChannelOptions(
        credentials: ChannelCredentials.insecure(),
        keepAlive: ClientKeepAliveOptions(
          pingInterval: Duration(seconds: 1),
          timeout: Duration(seconds: 10),
          permitWithoutCalls: true,
        ),
      ),
    );
    // stub = MetadataClient(channel);
    final clientConnection = await channel.getConnection(); // I expected method like server connection or something similar
    if (clientConnection.) {}
    await channel.shutdown();
  }
}

I was expecting that grpc will have method which return state of connection to the ip server maybe.

0

There are 0 best solutions below