6

I've been searching about configuring Flutter to connect to localhost in a real device, but I haven't found anything.

I always get "Conecction timed out" when I make try to connect to the server in my localhost.

I've tried the application with the emulator with 10.0.0.2 and it worked, but now I want to try the connection in my device and it seems IMPOSSIBLE!

This is the error I get:

SocketException: OS Error: Connection timed out, errno = 110, address = 192.168.0.125, port = 41814

Please! It can't be such a difficult thing, I guess...

I'm using a Spring Boot server and Flutter. My device is OnePlus 6T.

When I use postman it responds fine, Idk what is happening here.

enter image description here

8
  • Your setup is unclear and we need to know it. Tell on which device your Flutter app is running on. Then tell on which device your server is running on. Commented Oct 20, 2020 at 9:09
  • My device is a OnePlus 6T with Android 10 and the server is running in my PC with spring boot. Commented Oct 20, 2020 at 9:45
  • Then the client should use local ip of server computer and it looks as if you are using that. Try if a browser on your Android device can connect using that ip. Also try a browser on your pc. Did you bind your server to a local ip so it does not accept other connections? Switch off the firewall of your pc for a test. Commented Oct 20, 2020 at 9:52
  • As I saw in some examples, I tried to launch the server in 0.0.0.0:3333 and it continued working fine in postman. I also tried to access to that ip in a browser and in the device says "Connection timed out" and in the pc says "connection refused". Commented Oct 20, 2020 at 10:04
  • Firewall....... Commented Oct 20, 2020 at 10:59

2 Answers 2

2

If u mean Now you're using local server (ex. xampp) and want to test on real device Try this one https://ngrok.com/

Sign up to request clarification or add additional context in comments.

1 Comment

Had this problem as well. After setting up ngrok simply write 'ngrok http 9000' with 9000 being my localhost server. Then just copy the entry labelled Forwarding and use that for your requests.
1

This solution only when you have WiFi-isolation enabled in Router. Otherwise, if you put your local IP address API hosting url & to flutter, it will work!

STEP 1

I had the same issue and I resolved it like this. By default (highly likely) your router comes with WiFi-isolation enabled. This is a security feature. First you need to turn off this & save settings. Power off the router for >= 1 minute and & turn it on.

Router WiFi-isolation setting

STEP 2

Then you need to add two new rules to your firewall. Allow rules as Port-TCP-inbound and Port-TCP-outbound rules with the hosting port (e.g. 8000). IP should be kept 'Any' & allow for public/private/domain. In your server API configure your application to run in your local IP with your above configured Port number (8000). It should be like this.

.NET Core Web API hosting URL

STEP 3

In your flutter application set your URL to your local PC IP & Port.

Flutter post request

Then run your API and flutter application. Your local IP-Port configuration will work for emulators, android devices & web. I don't have iOS device to test. It should work there as well.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.