0

I have created two dropdown boxes one selects game and other servers. image of app

All i want to do is to know if there is a way to ping a server and get the latency, probably something like this in dart/flutter.

Edit: just installed the dart_ping lib and ran this code.

  void main() {
    runApp(const MyApp());
    pingIt();
  }

void pingIt() {
  var ping = Ping('google.com', count: 5);
  print('Running command: ${ping.command}');
  ping.stream.listen((event) {
    print("response : $event");
  });
  print("$ping");
}

It runs without any error, but the console says there are no responses from the server.

    I/flutter (13831): Running command: ping -O -n -W 2 -i 1 -t 255 -c 5 google.com
I/flutter (13831): Instance of 'PingLinux'.
I/flutter (13831): response : PingError(response:PingResponse(seq:1), error:RequestTimedOut)
I/flutter (13831): response : PingError(response:PingResponse(seq:2), error:RequestTimedOut)
I/flutter (13831): response : PingError(response:PingResponse(seq:3), error:RequestTimedOut)
I/flutter (13831): response : PingError(response:PingResponse(seq:4), error:RequestTimedOut)
I/flutter (13831): response : PingSummary(transmitted:5, received:0), time: 4102 ms, Errors: [RequestTimedOut, RequestTimedOut, RequestTimedOut, RequestTimedOut, NoReply]

So what should i do now and how can i know how many responses were received and how many were lost. How do i actually get ping does the lib contain a method that returns the ping or is there another way to do so.

By the way, I'm testing it in an android emulator.

iw2d
  • 1
  • 1

2 Answers2

0

If you are using Android Emulator to test this code then, you need to know that you can not ping from android emulatorcheck here. Use phisical device to test it.

Zajko04
  • 41
  • 1
0

Latest version of dart_ping works. I have tested it on physical android device with google.com, works as expected.

Vijay
  • 29
  • 3
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 29 '22 at 06:41