I've written an FTP service for Android, using Apache Commons-net 3.3.
When I run it on the emulator (with sdks 17 and 8, i.e. Android 2.2), all goes right; but when I run it on a LG P350, which mounts Android 2.2, the following code throws a SocketException with a timeout message:
ftp.connect(host, port);
where ftp is an istance of FTPClient. Arguments are: 192.168.0.100 (my notebook IP address) and 21 respectively.
I repeat: the same code is working under the emulator, and my phone is WiFi connected to the same network of my PC, pinging each other.
Someone can guess what is the issue?
Can you try connect to your Pc's Ftp port different apps ? Maybe you should change your router firewall settings. Because when you try from Emulator, it's connect same Ip address but when you use your phone this request goes on the router.
I think, firstly you can try with this apps connect your Pc. I believe that you can't reach your Pc. Try and share what it do please..
You can use this apps..
https://play.google.com/store/apps/details?id=com.glasertech.android.nettools&hl=tr
Is your phoe rooted?
Otherwise I think that you are not allowed to do that on your device.
Try a port above 1024.
Probably this will fix it.
Related
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 have a Tomcat server running on Localhost. My app can access it in the emulator using 10.0.0.2:8080. But when I connect a device it can't access the server.
I've seen some similar questions but couldn't get this working. can someone give me the steps on what to do?
we use 10.0.2.2:8081 because 127.0.0.1 is reserved for the emulator, however, when you need to try the application through a real device you need to change the URL to your PC IP
go to CMD and run ipconfig, look for IPv4 address, this IP you will use it..
add it to the URL for example: http://192.somethin.somthin.somthing:8081/the-location.php
P.S: you should set your firewall off and turn off any antivirus
The device may not be on the same network as the Tomcat server. Does your network provide VPN access? If so, try installing an Android VPN client (Junos Pulse is a good free one). Connect your device to VPN and try again.
10.0.0.2 looks like an internal address. The emulator is likely able to connect because the machine on which it is running is connected to the network. The actual device needs a direct connection as well. VPN should solve that.
I have an Android app running on a phone that's connected to a host machine over USB. The phone will always be connected to the machine and I need to go an HTTP request to the machine. Working in the emulator, I can access the webserver running on the computer using the IP address of 10.0.2.2 and that works fine. However running the same app on the phone, I get a SocketException of Network unreachable. The phone doesn't have a SIM card in it, nor does it have a wifi connection, I need the HTTP request to just go over USB to the computer. Is this at all possible? If so, what am I doing wrong.
I'm using standard HttpClient code, nothing special, which works absolutely fine if I run it on the phone using a wifi connection, so I know that's not the problem.
I ended up abandoning this and basically polling the phone for the new content I wanted from the computer using adb.
Reverse Tethering! not sure if it works. I never tried it. This thread might help:
https://android.stackexchange.com/questions/2298/how-to-set-up-reverse-tethering-over-usb
This Android app + Windows host app should do the trick:
http://www.codeproject.com/KB/android/UsbPortForwarding.aspx
I have a tomcat web server running on my local machine. I also have a HTC desire and a Galaxy Tab. my problem is, I cannot connect from my real android device to my local machine. When I try to connect using the emulator, everything's fine. Emulator works with communication to the address:
10.0.2.2, but the real devices don't
Does someone know the solution, or why there's the problem?
You have to get the exposed IP address of your local machine and connect to that. If you are behind a router, you will have to make sure that it allows the packets to pass.
Are you using network or WiFi? You should be on WiFi and connecting through the same router to have 10.0.2.2 accessible.
Also make sure you have your local machine's incoming port (I'm assuming 80) open and reachable from the outside.
I'm sending a POST to my development machine and it works with 10.0.2.2 in the emulator, but I can't get it to work when installed on my phone - the connection always times out. I tried 10.0.2.2, 192.168.1.3 (my computer) and my public IP..
I turned off the firewall and I tried forwarding port 8000 which is the port my web server is listening on.
Which IP should it be? Is port forwarding what I need to do? I have no clue how routers and my internal network work.
As you are using the same connection for your pc as well as emulator so as a result you can browse 10.0.2.2(aka localhost)
But when you are deploying it in a real handset you are facing the problem.
Make sure that your device and server share the same connection.
Use WIFI so that your device can detect 192.168.1.3
Hope it will help you