point-source / dart_ping

Multi-platform network ping utility for Dart
31 stars 14 forks source link

Not working while mobile data connected #17

Closed VatsalLahagora closed 2 years ago

point-source commented 2 years ago

Just to clarify, do you have mobile data and wifi connected simultaneously or just mobile data? Are you trying to ping a local or remote resource? What error are you getting?

Rosco89 commented 2 years ago

Same here. Wifi turned off, using only mobile data. Error is NoReply. Testing google.com

point-source commented 2 years ago

Android or iOS? Which OS version? Real device or simulator?

Rosco89 commented 2 years ago

Android or iOS? Which OS version? Real device or simulator?

Android real device. Android 10.

point-source commented 2 years ago

Thanks for the details! I'll check it out

point-source commented 2 years ago

Oh, one more thing.. Can you download a terminal emulator app and run "ping google.com" and see what it outputs? Then, have dart_ping output the command it is using by calling the .command getter and run that command in the emulator (it will have several flags on it). Compare that output to the other one. This will help diagnose if it is a configuration problem, binary problem, OS problem, or library/app problem.

If any of those steps don't make sense, just lmk. Thanks!

Rosco89 commented 2 years ago

Of course! I check tomorrow @ workplace.

Rosco89 commented 2 years ago

I downloaded termux, and when I run ping google.com command I got no response when I use mobile data only, ping works perfectly when using WiFi. So this behaviour is not your package's fault. Maybe something wrong with APN settings. I'll write if I can solve the problem, maybe it solve @VatsalLahagora problem too.

point-source commented 2 years ago

Thanks for testing that. For what it's worth, it does appear to work over mobile on my android 11 physical device. So it's definitely possible.

Rosco89 commented 2 years ago

After search I found, that my mobile service provider (Telenor Hungary) do not allow pinging.

This is my solution, maybe this helps for @VatsalLahagora:

Ugly but working.

if (widget.networkType == NetworkType.CELLULAR) {
      /// If network is cellular
      for (int i = 0; i < 3; i++) {
        PingData pingData;
        final stopwatch = Stopwatch()..start();
        await Socket.connect(data.ipOrDomain, 80, timeout: Duration(seconds: 1)).then((socket) async {
          socket.destroy();
          pingData = PingData(error: null, response: PingResponse(time: stopwatch.elapsed));
        }).catchError((error) {
          if(error.toString().startsWith("SocketException: Failed host lookup")) {
            pingData = PingData(error: PingError(ErrorType.UnknownHost));
          } else if(error.toString().startsWith("SocketException: Connection timed out")) {
            pingData = PingData(error: PingError(ErrorType.RequestTimedOut));
          } else {
            pingData = PingData(error: PingError(ErrorType.Unknown));
          }
        });
      }
    } else {
      /// WiFI, where everything is working
    }
point-source commented 2 years ago

Ah sorry to hear that. The solution you came up with is likely the next best thing. Anything else I can help you with or can I close this?

Rosco89 commented 2 years ago

This is not my ticket, but I think the same problem occurring with @VatsalLahagora. I think this ticket is closable.

point-source commented 2 years ago

Fair enough. Closing due to lack of response from OP. Without additional information, cannot reproduce.