How do I fix the "failed to connect" error from Expo / react native?
Asked Answered
S

4

9

When I run my expo/react-native project and want to run it on my android phone through the expo go app, it gives me a connection error:

"Uncaught Error: java.net.SocketTimeoutException: failed to connect to /192.168.2.18 (port 19000) from /192.168.2.9 (port54394) after 10000ms"

error image

  • windows 10
  • node v16.18.1
  • expo 46.0.9
  • react-native 0.69.6

From help from multiple resources I've tried the following things, but nothing worked:

  • made sure phone and laptop are on same network
  • Add inbound rule in windows firewall to allow port 19000
  • disabled windows firewall
  • Changed network profile to Private.
  • set REACT_NATIVE_PACKAGER_HOSTNAME to the ipv4 address
  • run expo start --tunnel, this works. But not the best solution because it slows everything down
  • Connected phone through USB to laptop. Developer mode is on, enabled USB debugging and tethering.
  • run sudo ufw allow 19000/tcp
  • entered "10" as interface metric for Internet Protocol Version 4
  • removed .expo to clear cache(?)
  • I also have a mac, if I run it on there it works and can connect to it / open the app just fine.
Statis answered 24/12, 2022 at 15:11 Comment(2)
Hi have you found a solution to your problem? I'm running into the same issue.Spurious
@Spurious I forwarded my ipv4 address to the WSL ip address where the expo app is running on. Using this guide: learn.microsoft.com/en-us/windows/wsl/… Let me know if this is not enough and you're still stuck.Statis
C
3
  1. If you are using a cellular network and connecting your laptop through the same mobile hotspot, ensure your connection is set to public on your laptop.
  2. If your laptop and mobile are connected to wi-fi, the connection must be private.
Captor answered 30/4, 2023 at 15:47 Comment(0)
K
1

I was facing a similar problem when trying to connect to the Expo Go app on my device. The error I received was java.net.connectexception failed to connect to 192.168.40:8081 expo, which is very similar to the error described in the original question.

My source code host machine and the computer were on the same local network. After researching the error, I realized that it could be a firewall block on my Ubuntu 22.02 machine.

I have a program on my Ubuntu called “Firewall Configuration” that I used previously to learn how to configure servers. Upon checking the settings, I noticed there was an inbound block.

To solve the problem, I did the following:

I opened the “Firewall Configuration” program. I navigated to the inbound rules section. I changed the rule to allow traffic. After making these changes, the problem was solved and I was able to connect to Expo Go without any issues.

Please note that this solution may not work for everyone, as it depends on the operating system and network settings. Also, changing firewall rules can have security implications, so proceed with caution.

I hope this helps!

Kickshaw answered 21/2 at 13:3 Comment(0)
M
0

If you use an antivirus, you need to turn it off. It helped me. Sometimes antivirus may block your connection.

Mccahill answered 18/3 at 15:39 Comment(0)
F
0

Turns out inbound connections to node were blocked in Windows Firewall. Allowing it solved the problem.

Follow these steps:

  1. Open Advanced Security for Windows Firewall.
  2. Click the inbound rules tab.
  3. Look for node.
  4. Right-click on it then click properties (Make sure you select 'node' not 'node.exe').
  5. In the General tab, Select 'Allow the connection'.
  6. Apply the change.

Note: Ensure that your phone and laptop are on the same WIFI network.

Fatback answered 11/7 at 18:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.