Android HttpClient sending request to host machine over USB - android

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

Related

Connection refused error in Android

I was running my application fine.There were some changes in the network,like my router and internet connection got changed.Suddenly in the LogCat,I see an error like connection refused.I have provided the static IP still I get the same error.
I am running my server on my laptop and the app on the device. Intially I was able to access the application through the app and also through the browser.Can you guide me and does my Android device needs a new setting that I am missing?
Definitely, you faced some networking problem. So, the diagnostic is the same as for any connected device.
check local Android firewall - try to connect to some another server, like facebook.com or google.com
check your laptop firewall settings
draw your network schematic carefully and think what should be working and how
try tcpdump\wireshark to see what's actually going on the wire
Hope you win!
Well the static IP works not sure why it was not working before may be because I was using a LAN connection only for laptop not a same WIFI connection both for laptop and android device.

no dns via ipsec tunnel android 4.4.2 xperiaz C6603 racoon

I've setup a racoon server on my linux router. It was working ok with my xperiaz (C6603) road warrior. However after I applied the latest update to android 4.4.2 (firmware 10.5.A.0.230) it stopped working correctly. I have ping from the phone to each ip (local ip or internet) but when I use FQDN it can't be resolved. I can ping the phone from within my local network too. VPN is IPSec Xauth RSA. Checking with adb DNS server is correctly set:
getprop net.dns1
192.168.6.1
I also tried pushing the same ip as dns2 but no change. I also noticed that after closing the connection to the vpn server net.dns1 remains 192.168.6.1 however the phone is able to correctly resolve addresses. In few minutes it gets changed back to my 3g provider setting.
I tried to redirect all traffic through the tunnel via the advanced vpn setting (Forwarding routes = 0.0.0.0/0) and tried to set DNS statically via the same settings (DNS servers = 192.168.6.1). Even setting the DNS server to my provider's DNS addres didn't work which makes me think the problem is with the android itself.
DNS server is working as far as I can tell:
$ dig #192.168.6.1 dir.bg +short
194.145.63.12
Forwarding is enabled on my router so shouldn't be the problem. I've read about a bug in android but it's in android 2.x and seems to impact wifi connections.
Have you seen similar problems and as I'm not an expert with android and adb, can you tell me what commands are available in adb/shell to trace the problem? Phone is not rooted and it's not possible for the moment to root it.
UPDATE:
the tunnel is working ok when I connect via wifi hotspot. The problem appears to show only via my 3g carrier. Any ideas how to work around this?
After updating to 4.4.4 I still got the same problem. Further testing revealed that the problem is more likely to be in the Android rather than my 3g carrier. Over wifi the VPN worked flawlessly after using wifi tethering from another phone via the same provider it worked ok again so my 3g carrier isn't blocking anything.
Yesterday I finally rooted my phone and installed SDFix to restore full access to my SD card. Now VPN is working ok again even via 3g. I hope someone can confirm/reject that solution as I see no relation between vpn and sd card at all. However I experienced initially the problem with my update to 4.4.2 where Sony started to follow Google's policy about storage access.

accessing local host from emulator

i am using Genymotion emulator which is the most great emulator and the fastest ever, but i am trying to connect to the local host of my computer since morning, i tried both 192.168.1.30 (taken by cmd>ipconfig>ipv4) and 192.168.56.1 which is used by many genymotion users as they mentioned.. but all what i am getting is this message on the emulator's browser:
Forbidden
you don't have permission to access/ on this server
it seems like its a matter of permission, some thing related to Wamp server configuration, or may be to firewall or any thing, i just need to create this connection simply..
On an Emulator you can access localhost on http://10.0.2.2/you_php_script.php
You'll want to connect to 192.168.56.1.
Make sure that the service that you are running on localhost is bound to the 192.168.56.1 interface.
Make sure that you do not have a firewall running.

Access a Tomcat local server using android device

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.

Ftp connection working on emulator but not on actual device

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.

Categories

Resources