Could not connect to TCP port: Connection refused when trying to open Expo app on Android Emulator in WSL2 - expo

I've been following this guide https://medium.com/#pellea/using-adb-with-wsl2-7aebbb070a47 and so far have gotten to the point where WSL2 can see the emulator(s) running on Windows through Android Studios -> AVD manager. For example, on both Windows and WSL2, adb devices correctly shows:
List of devices attached
emulator-5554 device
However, when I go to my expo app and try to launch the Android emulator, I get the following error message:
Couldn't start project on Android: could not connect to TCP port 5554: Connection refused
This is after I've tried the following:
exporting ADB_SERVER_SOCKET=tcp:<MY IP>:5037 in my WSL2 profile(s)
Unblocking WSL2 vEthernet connections from my Windows firewall via (from the above link)
Set-NetFirewallProfile -DisabledInterfaceAliases "vEthernet (WSL)"
I've portforwarded 5554 from Windows to WSL2, as well as 5037 (from 0.0.0.0 to 127.0.0.1):
$WSL_CLIENT = bash.exe -c "ip addr show eth0 | grep -oP '(?<=inet\s)\d+(\.\d+){3}'";
$WSL_CLIENT -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
$WSL_CLIENT = $matches[0];
iex "netsh interface portproxy add v4tov4 listenport=5554 listenaddress=127.0.0.1 connectport=5554 connectaddress=$WSL_CLIENT"
The ports are as follows:
netsh interface portproxy show all
Listen on ipv4: Connect to ipv4:
Address Port Address Port
--------------- ---------- --------------- ----------
127.0.0.1 8081 172.25.38.171 8081
0.0.0.0 5037 127.0.0.1 5037
127.0.0.1 5554 172.29.149.0 5554

Just had the same issue with Expo.
Here is what fixed it for me:
Check for a process that uses port 5555 (Terminal)
netstat -ano | findstr 5555
Kill the process using its ID (PowerShell)
Stop-Process -ID [PROCESS_ID] -Force
Then it started working.

I had the exact same problem, but with a different setup (using Expo with the Metro bundler on a Mac). I worked around it by trying different virtual device images. Maybe the same can help you.
The virtual device that works with me so far is the one selected in this screenshot: https://i.stack.imgur.com/CFTJ0.png. The other two in the screenshot have the same problem. I don't really know the actual reason, must be something with port access with those other emulated devices.
Image details:
Name: 4 WVGA (Nexus S) API 29
API: 29
Target: Android 10.0 (Google APIs)
CPU/ABI (x86)
I'm sure other images work as well (or configuring the others somehow), i just haven't tried many more because it takes so long and they're so big.

Did you try to map port 5554 to Windows IP instead? (or localhost). The Android emulator is running on Windows, not WSL2, so the port proxy should be from WSL2 to Windows, not backwards.
Have you already solved it in another manner?

Related

Running code server on gcp cloud shell gives error when previewing

I'm trying to run code-server on gcp cloud shell. I downloaded the following version
https://github.com/cdr/code-server/releases/download/v3.9.2/code-server-3.9.2-linux-amd64.tar.gz, which I think is the correct one, extracted the contents and ran
code-server --auth none
This gave the following output
[2021-04-06T00:53:21.728Z] info code-server 3.9.2 109d2ce3247869eaeab67aa7e5423503ec9eb859
[2021-04-06T00:53:21.730Z] info Using user-data-dir ~/.local/share/code-server
[2021-04-06T00:53:21.751Z] info Using config file ~/.config/code-server/config.yaml
[2021-04-06T00:53:21.751Z] info HTTP server listening on http://127.0.0.1:8080
[2021-04-06T00:53:21.751Z] info - Authentication is disabled
[2021-04-06T00:53:21.751Z] info - Not serving HTTPS
Now when I try Web Preview -> preview on port 8080 nothing happens I just get a blank screen and on the code console I see the following error
2021-04-06T00:50:04.470Z] error vscode Handshake timed out {"token":"e9b80ff7-10f9-4089-8497-b98688129452"}
I'm not sure what I need to do here ?
In cloud shell editor, create a file with .sh extension, and install the code-server by using these steps:
export VERSION=`curl -s https://api.github.com/repos/cdr/code-server/releases/latest | grep -oP '"tag_name": "\K(.*)(?=")'`
wget https://github.com/cdr/code-server/releases/download/v3.10.2/code-server-3.10.2-linux-amd64.tar.gz
tar -xvzf code-server-3.10.2-linux-amd64.tar.gz
cd code-server-3.10.2-linux-amd64
To run the vscode.sh file using terminal:
./vscode.sh
If a warning “permission denied” comes, type chmod +x vscode.sh and then again proceed with
running the file.
To navigate to the folder:
cd code-server-3.10.2-linux-amd64/
To navigate to the bin:
cd bin/
To start the server :
./code-server --auth none --port 8080
Now you can see the VSCode IDE in your browser either by using web preview->preview on port 8080 option or the HTTP server link in your terminal.
My gut is saying that one must study this article (Expose code-server) in great detail. I think you will find that Code server is listening on IP address 127.0.0.1 at port 8080. Your thinking then is to access this server using Web Preview on port 8080 .... however ... pay attention to the IP addresses of your virtual machine. The IP address 127.0.0.1 is known as the loopback address. It is ONLY accessible to applications running on the SAME machine. My belief is that when you run Web Preview, you are trying to access the IP address of your Cloud Shell machine which is NOT 127.0.0.1.
If you read the above article, the story goes on to show how to use SSH forwarding to provide a front-end to whatever this application may be.

How can I get expo to connect to Android emulator with a non-localhost ip address?

I have an Android Emulator running on Windows on port 5554.
I am running expo inside WSL2. I have verified that I can access my Android Emulator on WIndows since if I type in:
# 172.22.80.1 is the IP to Windows from WSL2
telnet 127.22.80.1 5554
it shows me the same "Android Console: Authentication required" prompt as if I did it in my Windows PowerShell.
However, when I click on "Run on Android device/emulator" from the Metro Bundler web page, it throws me:
Couldn't start project on Android: could not connect to TCP port 5554: Connection refused
It seems like it's trying to access the emulator via localhost:5554, but I would like it to connect to $SPECIFIED_IP:5554.
Is there an env var where I can change this? FWIW I am using a Managed Expo project.

Local Server not loading in Ubuntu VirtualBox

I have laravel app which is running in my windows local server. This laravel app is running port:80. I want to load this app in my Ubuntu VirtualBox.
My IP Config:
IPv4 Address : 192.168.8.157
Subnet Mask : 255.255.255.0
Default Gateway: 192.168.8.1
I have config my virtualbox as Bridged Adapter. In my /etc/hosts (ubuntu virtualbox), I have this :
127.0.0.1 localhost
127.0.1.1 asus
192.168.8.157 v2.my.local
I have made a hello word app (node.js) in my local windows which is running on port :3000, and it is running in my VirtualBox by typing v2.my.local:3000, but if I type v2.my.local on my VirtualBox, it is not working (although app is running on windows local machine). it says:
This v2.my.local page can’t be found
Any suggestion? Thanks in Advance.
May be windows firewall blocking connections via port 80. turn off firewall and try it, if it works. Start windows firewall and add firewall rule to allow connections via port 80. If your windows version is 10 then, it will block all virtual box related connections. make sure to add correct rules.

How to redirect specified packet using WFPSampler of WFP (Windows Filtering Platform )

Could you tell me how to redirect internet connection to local proxy in my PC ?
I got WFPSampler from the below URL.
https://github.com/Microsoft/Windows-driver-samples/tree/master/network/trans/WFPSampler
I'd like to redirect internet connection to local proxy in my PC using the WFPSampler without changing proxy setting of IE.
My system is the below.
[System]
OS: Windows 8.1 (192.168.1.1)
Local proxy: squid (port:3128)
[Background]
I performed the below command. But it did not work.
WFPSampler.exe -s BASIC_PACKET_MODIFICATION -l FWPM_LAYER_OUTBOUND_TRANSPORT_V4 -ipla 127.0.0.1 -iprp 80 -mpdp 3128 -ipp TCP -v
Thank you for any help
Regards,
Y.N
Consider using FWPM_LAYER_ALE_CONNECT_REDIRECT_V4 layer as it is designed for the purpose of redirection.

Wamp server can't bind to port 80 error

I'm having a very similar error to Getting an error when starting WAMP - "VirtualHost *:80 -- mixing * ports and non-* ports with a NameVirtualHost address is not supported, proceeding with undefined results"
I'm getting the same
Only one usage of each socket address (protocol/network address/port) is normally permitted. : make_sock: could not bind to address 0.0.0.0:80"
error message in the event logs viewer. I tried the fix of disabling skype from using port 80 however when I do that nothing comes up in the console. I am using 64 bit wamp, im in a 64 bit windows 8.1 laptop.
Edit: Problem resolved, changed Listening on 80 to 8080 in httpd.cfg
There is a menu item on the WAMPManager icon ( the one in the system tray ) called Test Port 80
You get to it by
wampmanager -> Apache -> Service -> Test Port 80
This will load a command window and show you the name of the other application that has captured port 80.
Then you have to work out what to do about it of course.
Also as far as I am aware the Windows 8 tiled version of SKYPE does not have any way of being configured to stop using port 80. But if you uninstall the Tile version of SKYPE and install the normal Windows version, that allows you to configure it so it will not attempt to use port 80 or 443.
If you really cannot find the wampmanager icon try this instead
Try this
netstat -anop TCP | find ":80"
tasklist /FI "PID eq 999" /FO TABLE /NH
replacing 999 with the PID number from the previous command that is using port 80.
Other programs can mess with this.
Are you using Skype by chance or any other program.
If you are just turn it off and then launch wamp and then launch your program.
Open Command Prompt and run netstat -ano | findstr :80
That will list all connections and their process ID (on the right) that are using port 80. Match them with process IDs in your task manager and close them.