I have a SFTP server in my application provided by the Apache SSHD library, which I can access with no problem via the Wifi network connection, but in this project I need to make this server accessible via an ethernet connection.
I have a computer with the ip 169.254.2.2 and I connect it to the Android device via an USB to ethernet adapter (which upon connection becomes the eth0 interface).
Since it is a rooted device that will run the application, I'm using the su process to set the configuration of the network interface with the following commands:
ip addr add 169.254.2.1/24 dev eth0
ip route change 169.254.2.0/24 via 169.254.2.2 dev eth0
//I'm using route change because as soon as I add the ip
//it creates a route table to 169.254.2.0
The settings above seems to be working because both the ethernet icon starts showing on my device and ifconfig command confirms the assigned ip, but when I try to connect to the SFTP server from the computer the connection times out.
So I tried to ping the computer via the device monitoring the network with Wireshark:
Both the request and the reply got delivered fine, but when I try to do the other way around (the computer ping the device) the ping request times out and in Wireshark I get the following:
Android seems to be refusing or ignoring all the requests via the ethernet adapter. Is there a reason to it and/or another way to set my connection so this don't occur?
Additional devices details:
Moto Z Play with Android 7.1.1;
Moto G with Android 5.1 (ethernet icon doesn't show but the connection works the same)
Related
I downloaded Apache 2.2 from here I know that this is old version but anyway I need it. Then I launched Android emulator and tried to access to server and it worked. I used 10.0.2.2 IP address with 8080 port.
Next, when I try to connect to server using PC on which I launched the server, it works if I provide IPv4 address of PC for example 192.154.1.23:8080.
Well, when I try to connect to server using my physical device (my mobile phone) I can't do that even if I try IPv4 address of my PC with 8080 port. It just tells me about time out.
What should I do to connect to server from my phone?
P.s. I use same WI-FI network on both devices
Solved it.
Well first of all you need to set type of your connection to private and make sure that this is trusted network, for example your home network or your own WI-FI. But you also can do it with public network but this is too risky!!!
Then go to Firewall settings and allow Apache application to communicate with other devices. Choose it in the table of allowed app and features and check the box for private network, then press OK. I recommend to restart Apache server.
That's it! Now you can connect to server using IP address of your PC, on which you installed Apache server, from any device like other PC or mobile phone but you have to be in same local network. If you want to access your server globally you need to ask your ISP (Internet Service Provider) to get static IP address to make it visible in global network.
I am trying to make a post request from my desktop computer onto a Unity App with a http listener on my phone.
The Unity app listens on 0.0.0.0:4444. I send data to this via my python application using
x = requests.post("http://192.168.0.98:4444", data = somestring))
where 192.168.0.98 is the ip address of my phone. The two devices are connected to the same network. I have tried - turning on USB debugging, pairing the devices via adb and the 6-digit pairing code, connecting the devices via adb and the instructions here https://developer.android.com/studio/command-line/adb#wireless.
The application works perfectly when I am running Unity on my desktop on the same computer as the python code, but when I run it on my phone, my python code encounters.
HTTPConnectionPool(host='192.168.0.98', port=4444): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x00000253FEB996A0>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it'))
Well I just solved this two minutes later, just had to change the listener to 192.168.0.98 as well
I am using Android Studio version 3 on Window 8.1. There is XAMPP installed to host php api on localhost. I am trying to access the localhost api from Android Studio.
In the host name, I used IPv4 Address.
When I access it from Android Version 3, using Emulator. There is no problem at all. I am using Volley for api calls.
When I try to access using Real device through USB...I always get timeout error.
I am using Real device because my RAM is very low.
Please let me know if you need more info.
Update 1
I can confirm that Android 2.2.3 is working fine to run the apk on read device through USB
I disabled the Firewall and everything is working perfectly.
Your access to local host via IPV4 works on emulator because your emulator and the host are on same network. It gives timeout on real device because, real device is not connected to same network as your host by just connecting through USB.
There are two approaches:
Ensure your device and host share the same network. It could be by connecting your device to host network through Wifi.
If you cannot connect your device to the same network due to some constraints, then you can run following command:
adb reverse tcp:<localhost-port> tcp:<localhost-port>
Then use localhost instead of IPV4 in your URL
Your Network firewall Blocks the connection to localhost. To resolve this you can do :
In windows
1st Method Add Inbound rule (Recommended)
Create a new inbound rule with Windows Firewall with Advanced Security. The type in this case would be port, then on the next page you enter 8080 as the port. On the next page select either "Allow the connection", or "Allow the connection if it is secure". Select when the rule applies, and finally give the rule a name.
Connect the localhost api through the new allowed port.
Use ip-address of the localhost instead of localhost.
2nd Method Turn of firewall.
In Linux
1. Add IPTable Entry
You can learn adding incoming and outgoing rules using ssh and http in Linux here
I am programming an Android app which connects to a TCP server running on my computer using sockets. This works perfectly fine as long as both my computer and my smartphone are connected to the Wi-Fi of my router.
I want it to also work when my computer and my phone are not connected to the Wi-Fi. Therefore I configured a Wi-Fi hotspot using hosted network on my computer. My smartphone recognizes the Wi-Fi and is able to connect to it. But now my app can't connect to the server running on my PC although I changed the code to the new IP that I got by using ipconfig on my PC.
I downloaded an app named "Fing" from the Google play store. The app shows all devices in a network. It does show my computer under the right IP address. I don't understand why my app can't connect to the server running on the PC.
On the one hand, I don't think that the problem is in the app's code, because it works on the router's Wi-Fi network. On the other hand, I doesn't seem to be a setup mistake either, because Fing is detecting my PC.
Do you have any ideas what the problem might be, or any other solution for my needs?
I actually wrote the TCP server myself using c#. I configured the Server to listen to all of my computers networkinterfaces usingIPAdress.IPv6Any. I also did configure it as dual mode socket so it can accept ipv4 and ipv6 connections. I will post the code when i am back home. So the TCP server also looks ok to me.
I try to deploy a worklight application into my android device (HTC Desire), without any hope I get the following error:-
Request timeout for [ANDROID IP :8080/console/apps/services
Default options: on failure timed out for
http://ANDROIDIP:8080/console/apps/services...
Make sure the host address is available to the app (especially relevant for android and iphone apps]
I find my android IP address via whatip.com and I configure my application descriptor xml file with it.
it works with android emulator when I use the following
<worklightServerRootURL>http://10.0.2.2:8080</worklightServerRootURL>
but not with the mobile device
any advice?
worklightServerRootURL should point to the public IP address of the host machine, not to the device IP.
The device and Worklight Server must be in the same network (public Internet, wifi...).
10.0.2.2 is a special address that only works on the android emulator. On the emulator, it is routed to the host where the emulator is running. On an actual device, this address won't be routed anywhere.
As Idan said, the Worklight server must be reachable from the Android device. This usually means that either the Worklight server has an address that is reachable from the internet, or that the android device has a wifi connection to the LAN where the worklight server is running.
Assuming that you are trying to test using the test server in worklight studio, first determine your computer's IP address. If you are behind a NAT router, whatip.com returns the IP of the router, not of your computer. Use ifconfig (ipconfig on windows) at a command line to determine your computer's IP address. Your computer may have several IP addresses. It is important that you choose the ones that corresponds to the LAN where you will be connecting your Android device. If you are unsure which one this is, you may need to look at your router's configuration. Next, verify that your computer's firewall has port 8080 open. Then connect your android device via wifi to the same LAN as your computer.
To verify that your device can reach the worklight server, try opening the worklight console in the phone's browser. (http://[IP of computer]:8080/console) Once that works, you should be able to use the same IP in the worklightServerRootURL to build the app so that it will work on that device.