How to get ping in flutter?

Viewed 802

Is there any way to get ping of ip address in flutter?

I tried to use dart_ping package but this package was broken.

1 Answers

Good news, dart-ping is alive): https://pub.dev/packages/dart_ping Also you can use dart.io class Socket and it's connect method

    Socket.connect('192.168.1.101', 80, timeout: Duration(seconds: 3)).then((socket){
    // do what need to be done

    // Don't forget to close socket
    socket.destroy();
  }).catchError((error){
    print(error.toString());
  });

But it will work only if someone is listening target port. In some networks it's the only way to see if the server is up, because "ping" is blocked due to security reason.

Related