15

I'm using a real device (not an android emulator) backend: MongoDb Atlas, API: strapi-beta, getting this error: I/flutter (30720): SocketException: OS Error: Connection timed out, errno = 110, address = 192.19.170.13, port = 47763 (found a lot of similar questions but none of them were using a real device for testing)

    try {
      var ip = '192.19.170.13';
      setState(() => _isSubmitting = true);
      http.Response response =
          await http.post('http://$ip:1337/auth/local/register',
 /* I've also tried using localhost(it didn't work) everyone suggested to use my loopback adapter's (Ethernet's ip address) even that isn't working.*/
 body: {
        'username': _username,
        'email': _email,
        'password': _password,
      });

      final responseData = json.decode(response.body);
      setState(() => _isSubmitting = false);
      _successSnackBar();
      print(responseData);
    } catch (e) {
      setState(() => _isSubmitting = false);
      print(e.toString());
    }
  }
Madhav Tripathi
  • 159
  • 1
  • 2
  • 7

12 Answers12

7

check your device network connection(emulator or real device) and machine network connection(computer) are same.

  • mobile data turn off
  • user wifi data which are used on your machine.

problem solved.

AK IJ
  • 492
  • 4
  • 10
4

Well, if you are doing the tests with a local server and you are on windows. The error is probably due to the windows firewall. You could disable the firewall and it should work or add a rule to the firewall to allow tcp access to the mentioned port.

  • To add to this, you can specify the inbound and outbound rules of your firewalls. Navigate to window defender firewall, choose advanced settings, you can find inbound and outbound rules. Choose rule type port, you can specify TCP or UDP protocol, choose port or choose all ports, allow connection, then just name the rule. Do this for both inbound and outbound rules. This will allow your android device to connect to nodemon server you're running. – ThomasH.Allen Jun 25 '23 at 08:32
  • Man you're such a big savior, I was stuck since two hours into the issue and was almost going to quit! – kahan x10 Aug 26 '23 at 16:43
3

If you're working on Chrome, you need to go to

chrome://inspect/#devices

and add your port to 'Port Forwarding' like this

enter image description here

And make sure you have USB Debugging on your device.

1

I had also the same issue with my an Android Device. i.e. IP Address Link works fine in Localhost but not works on physical devices.

So I found that for use yours IP Address link on Physical Devices (Android Devices) you must need to Host your website(mostly WebAPI's) on WAN Network to access yours IP Address links.

So answer is Host your website (mostly WebAPI's) on WAN Network.

  • the same issue I were facing, but my app running on an emulator, not on real devices, so your solution will work for that or is there any other solution to run on real devices too. – s.j Jun 14 '21 at 08:16
0

I had the same issue with the emulator and the reason for my problem was the IP.

Can you check if you have connectivity to that IP in the device, without using the flutter application?

My problem was trying to connect to the host localhost using 127.0.0.1, and found this page: https://developer.android.com/studio/run/emulator-networking

guren
  • 122
  • 2
  • 9
  • 1
    I've already said I'm not using an **emulator**, and the above link doesn't helps! – Madhav Tripathi Feb 11 '20 at 08:03
  • But have you tried to check if you have a connection to 192.19.170.13 without the application? The other part was to explain why I had the issue, the service I was looking for wasn't at the IP I was calling. It was just for context. – guren Feb 11 '20 at 10:54
0

Method 1:

  1. install apache2
  2. install curl
  3. access www and fixed with www.IP ADDRESS

Method 2:

  1. config your router NAT setting to your local IP address.
    Now you can use your Internet IP Address.
סטנלי גרונן
  • 2,917
  • 23
  • 46
  • 68
Mohsen Haydari
  • 550
  • 5
  • 20
0

I had this problem many times too. what i did was to use the hotspot on my android mobile i use for debugging to connect to the pc, and voila it works.

flochristos
  • 73
  • 3
  • 13
0

Well, what i did to fix this error was to turn windows firewall off, then I opened the needed ports in my router, and it worked!. Also you can set the inbound rules in windows firewall so that you don't need to turn it off

rats4final
  • 1
  • 1
  • 1
  • 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 May 17 '22 at 21:02
0

I had this issue occur when hosting both my Flask server and Mongo database locally, by moving the database to a separate device and hosting it there.

It should also be expected that if both are hosted on the same IP you would run into the same issue.

Vincent Casey
  • 178
  • 2
  • 11
0

turn your connection on pc to private not public and restart server then pick your pc ip by ipconfig command in cmd and use it as base url

  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 29 '22 at 06:13
0

So i was using mobile data and gave the ip of mobile data network when i switched back to my wifi i was getting this error what worked for me was i went to cmd typed ipconfig and copied my ip4 address and replaced it in the api url in the program

0

It could be a problem with your localhost web configuration alse. In .Net 6 I had the same issue and I need to specify the URL that the web should be bounded if DEVELOPMENT environment is used.

In Program.cs add the following:

if (app.Environment.IsDevelopment())
{
    app.Urls.Add("https://*:7176"); //after colon enter port that your web uses
}

Then in your Flutter project you will have to create the class:

class MyHttpOverrides extends HttpOverrides{
  @override
  HttpClient createHttpClient(SecurityContext? context){
    return super.createHttpClient(context)
      ..badCertificateCallback = (X509Certificate cert, String host, int port)=> true;
  }
}

After all, in main(), before runApp() method is called, override HttpOverrides.global with class you have created:

HttpOverrides.global = MyHttpOverrides();