On my Android emulator device I have deployed HTTP server on port 8080
> adb -s 127.0.0.1 shell
generic_x86:/ $ netstat -atn
Active Internet connections (established and servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp6 0 0 :::8080 :::* LISTEN
tcp6 0 0 ::ffff:10.0.2.16:47344 ::ffff:66.102.1.18:5228 ESTABLISHED
However, when I try to access it from the host the port seems to closed:
curl http://127.0.0.1:8080
curl : Unable to connect to the remote server
In my host Resource Manager I am not seeing any process listening on that port
Why is the port not visible on host?
The official documentation says that (thanks to #Selvin):
Each instance of the emulator runs behind a virtual router/firewall service that isolates it from your development machine network interfaces .
and then explain how to open specific ports by
Using network redirection
In my case implementation the steps helped
telnet localhost 5554
auth ... # with token
redit add tcp:8080:8080
quit
And voila, HTTP server has become available on my host machine.
Now,
Related
I did a question since I'm testing my react-native/express app by using usb debug on android and I'm still getting a network request failure:
How to connect to the express development server using adb reverse?
Since I couldn't find a solution I tried to read the docs and figure out how it's the communication among different parts.
Cases
Commands used are those described in React-Native docs but it could differs. Although I guess there are not too many options:
https://reactnative.dev/docs/running-on-device
https://reactnative.dev/docs/signed-apk-android#testing-the-release-build-of-your-app
Case 1: running only using the dev machine and emulator
Case 2: running using the usb debug
Case 3: wifi (I didn't try yet)
Case 4: uploading to play store by bundleRelease
Elements:
Dev machine:
Local host: 127.0.0.1
Local IP (from windows 10: settings, network & internet, wi-fi; eg 192.168.1.1)
Server
Device
Emulator
ADB
Daemon
Ports usage:
From my dev machine:
Server (eg 5000)
React-native: 8081 (default)
Daemon: 5037
From device: I guess is used only the 8081 port.
Emulator:
10.0.2.2 Special alias to your host loopback interface (i.e., 127.0.0.1 on your development machine)
10.0.2.15 The emulated device network/ethernet interface
127.0.0.1 The emulated device loopback interface
Connections
React-native emulator mounts over the 8081 port of the dev machine local host. Since it "replaces" the local host adress if you wanna access to another port you have to use the alias 10.0.2.2 (eg server running at 5000 will be: 10.0.2.2:5000).
Till then my app works well setting the communication following the instructions above mentioned. But when I try to use the USB debug I can't connect to the server and I'm getting puzzled about what's going on behind the scene.
I wrasp the idea of the emulator running as an isolated router to which is connected the tested device. I guess Daemon runs as a background process reloading every time that the server file is edited. But I can understand why I can't connect to the server.
Resources
Android
https://developer.android.com/studio/run/emulator-networking.html
Note that the same address assignments are used by all running emulator instances. That means that if you have two instances > running concurrently on your machine, each will have its own router and, behind that, each will have an IP address of 10.0.2.> 15. The instances are isolated by a router and can not see each other on the same network. For information about how to let > emulator instances communicate over TCP/UDP, see Interconnecting Emulator Instances.
Also note that the address 127.0.0.1 on your development machine corresponds to the emulator's own loopback interface. If you > want to access services running on your development machine loopback interface (a.k.a. 127.0.0.1 on your machine), you should > use the special address 10.0.2.2 instead.
Finally, note that the pre-allocated addresses of an emulated device are specific to the Android Emulator and will probably be > very different on real devices (which are also very likely to be NAT-ed, specifically, behind a router/firewall).
http://adbcommand.com/adbshell
https://developer.android.com/studio/command-line/adb
Locates emulator for each connection by a using a pair of ports (console/adb) in the range of 5555 to 5585
When the server starts, it binds to local TCP port 5037 and listens for commands sent from adb clients—all adb clients use > port 5037 to communicate with the adb server.
Adb graph connection of my own (this is in case of several devices connected but if I'm not wrong it'll work similarly to one device connected):
devMachine: client -- server
-- daemon -- || -- daemon -- : running device 1
-- daemon -- || -- daemon -- : running device 2
-- daemon -- || -- daemon -- : running device 3
https://developer.android.com/training/articles/security-config
I have a Vagrant box which runs a nodejs server with port 3000 which I have forwarded to my host with vagrant ssh -- -L 3000:localhost:3000. For some reason, using 10.0.2.2:3000 on the Android Emulator does not reach this server. Is there anything else that I have to do to access an already-forwarded ip and port from within an Android Emulator instance?
It does work from my host, but not within Android Emulator.
Thank you!
This turned out to be my application's issue. From nc in adb shell I can access the interface in question.
I try to use SSH on Android the first time, i had read a lot about it but i cant find much, only from Android to Computer. Maybe someone can help me here:)
I have coded an APK for my own Android Device wheres create an SSH Connection over my PHP Script using Proxy Server.
I use an Debian VPS as Proxy Server. With this IP, the Android creates an Proxy.
Now i use this Comment:
ssh -N -L 34836:127.0.0.1:34836 newgenerateduser#23.106.XXX.XX
Port is generated also random every time i create an new proxy over PHP Script.
I use now an Virtual Machine with Ubuntu and enter the Comment in my Terminal with the Passwort after asking.
I start my VNC Client and want get remote Control over my Android device using VNC or SSH with this IP and Port:
127.0.0.1:34836
I got this Message:
lxs#linux-virtual-machine:~$ ssh -N -L 34836:127.0.0.1:34836 newgenerateduser#23.106.XXX.XX
newgenerateduser#23.106.XXX.XX's password:
channel 2: open failed: connect failed: Connection refused
I also tried using localhost instead of IP.
There are special requirements for the Proxy Server? Or just Port blocking on it?
Thanks for your help!
My application embeds a local http server that can be accessed through the loopback device at URL: http://127.0.0.1:8080/
It works fine with WiFi enabled, it also works fine with no external network (no WiFi, no 3G) but it fails when WiFi is disabled and 3G enabled.
Connecting through adb shell and executing "netcfg" I can see that the loopback device is always enabled:
shell#android:/ $ netcfg
...
lo UP 127.0.0.1/8 0x00000049 00:00:00:00:00:00
...
Alos "ping 127.0.0.1" continues to work while switching on/off the WiFi or 3G.
Any idea?
UPDATE:
Adding to the puzzle. From my dev computer I forward the tcp port:
$ adb forward tcp:8080 tcp:8080
Then I try to connect from my PC using http://127.0.0.1:8080/. It works, but when it continues to fail when using a browser running on the android device.
UPDATE 2015-06-01:
When working on 3G I see on adb logcat lot of related errors similar to:
W/ContextImpl( 504): Calling a method in the system process without a qualified user: android.app.ContextImpl.sendStickyBroadcast:1239 com.android.server.TelephonyRegistry$3.onReceive:818 android.app.LoadedApk$ReceiverDispatcher$Args.run:788 android.os.Handler.handleCallback:725 android.os.Handler.dispatchMessage:92
and
E/CellLocation( 8336): create GsmCellLocation
It doesn't make any sense to me to trigger Gsm activity to connect to the loopback device.
UPDATE 2015-06-01 (2):
I managed to install wget in
/data/data/com.XXXX.yyy/files/appFiles/bin
Then I connect through "adb shell" -> "run-as com.XXXX.yyy" and finally execute:
wget -O - "http://127.0.0.1:8080/"
I works properly so I can discard any weird security setup that disables loopback access on localhost, so I guess it has something to do with WebView/WebViewClient trying to wrongly use a 3G external proxy to access the loopback. Now I'm wondering whether it's possible to disable the proxy on WebView.
Finally it looks it was a problem with the WebView trying to access an external proxy even for the lookback interface. I fixed the issue following the solution proposed at: WebView android proxy
I am just getting started with Android Webdriver.
I have successfully setup my first tests and I am using an HTC One V to run them, after following all the steps mentioned here: https://code.google.com/p/selenium/wiki/AndroidDriver
However, on my local host, I am also running a Jenkins instance which is normally started on 8080, and I would like to keep Jenkins running on this port and change the port of the Android Webdriver server.
Is it possible to have the webdriver hub running on the local host on a port other than 8080?
Yes it is possible to use another port on the PC.
Try changing the value in the adb forward command to something like: adb forward tcp:8090 tcp:8080 which would mean the port on your PC to use would be 8090 in your scripts, etc. [Remember to start WebDriver running on the Android device first.]
You can easily test this connects OK by using a web browser to connect to http://localhost:8090/wd/hub/status/ the response will appear as a web page with something like {status:0}
Here are the details from adb:
adb forward <local> <remote> - forward socket connections
forward specs are one of:
tcp:<port>
localabstract:<unix domain socket name>
localreserved:<unix domain socket name>
localfilesystem:<unix domain socket name>
dev:<character device name>
jdwp:<process pid> (remote only)