Android emulator cannot connect with local tomcat server with HttpURLConeectioin - android

I'm doing a project to connect Android with local Tomcat server. But now I'm facing a problem for about 1 week. Who can help me..Thanks very much!
I use the newest android API and Tomcat 7.0. When I start Tomcat server. I can access the Tomcat homepage through emulator browser with url:(http://10.0.2.2:8080). But when I use HttpUrlConnection in the code. I cannot get the successful connection. I also use httpurlconnection to access www.google.com and www.android.com. I cannot connect them either.I use HttpURLConnection.HTTP_OK to see whether it make a successful connection. I also see the Connected is false for HttpURLConnection instance I make.
By the way I also add the internet access permission for it in AndroidManifest.xml before tag.
Thank you very much! Help me. It's emergency.

I recently had this problem. As mentioned above, (on Windows) start cmd, and use ipconfig to find the PC's IP address. Also, due to my Eclipse/Tomcat configuration I needed to have my Eclipse project name in the URL. The URL I used was like this: http://192.168.1.2/myEclipseProject/ServletName
Also, you may need to add the port to the ip address, if your Tomcat still has the default configuration: 192.168.1.2:8080

Related

AVD not able to connect to the internet?

I've tried running an app that fetches JSON data from the internet through an HTTP Request object, It showed
java.net.UnknownHostException: Unable to resolve host “api.github.com”: No address associated with hostname
as the Exception for every trial. Later I checked the internet connectivity in the AVD by running a browser. I wasn't able to access any site.
Is there any settings that I'll have to change in the AVD Manager so that I can access the in the Internet through the Virtual Device.
Help me out, Thanks in Advance.
If that is your exact error, I see what's wrong just from that.
Android API's, unlike any modern browser, requires explicit declaration of http or https.
You have to make sure the URL contains either of those protocols which you either can do by adding it into the URL manually, or adding this code before you create the volley request:
if(!url.startsWith("http://") && !url.startsWith("https://")){
url = "http://" + url;
}
You could replace it with HTTPS, but not all sites have https, so it's a generally good idea to default it to HTTP to not get errors from that. If you supply https but there's no HTTPS certificate, the website will most likely refuse the connection.
In my case , I received such error when the Emulator could not connect to the internet.
(Try browsing the internet using the Emulator to test its internet connection. suggested in https://teamtreehouse.com/community/unknownhostexception-unable-to-resolve-host-apidarkskynet-no-address-associated-with-hostname)

Android connectivity/network configuration

I have a WebService running in a remote VM inside my company's network.
I can see the JSON response using Chrome on my laptop by typing the url in the address bar (http://VMaddress/servicename/).
However, I cannot do this using the Android emulator. My company uses a proxy and I have already defined it in both the emulator launch window and inside the Android application itself. I can connect to Google and stuff, but I still cannot connect to the remote VM.
So my question is:
How is networking handled in the Android emulator? I know it defines a different ip for localhost, but shouldn't I be able to at least see the JSON response in the emulator browser (since I defined the proxy that would allow me to access the Internet)?
Doesn't the emulator run on my laptop's connection?
I get a 403 forbidden response using both the emulator browser and the Android application.
I also tried another WebService URL (http://api.geonames.org/citiesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&lang=de&username=demo) and I get a 200 response code, so my application is correctly accessing the Internet).
thanks in advance
---EDIT---
I snooped around in my connection settings in my laptop and going into the Proxy Settings in Chrome I had an exception in the proxy for the VM where my server is.
Removing that exception gives me the same 403 forbidden error I have in my emulator.
How can I apply the same exception to the emulator?
Somehow I managed to "resolve" this.
I am not entirely sure this is the reason, but I followed these steps. The emulator must start while there is no network available.
I also have the DNS servers from my company set in the Launcher menu using the options:
-dns-server server1,server2 (got the values from ipconfig /all in a command prompt). It will not work for me without these settings.
and I configured the proxy manually in the emulator by creating a new APN following these steps.

Spring Android Connection Refused ECONNREFUSED

I am trying to make a connection from my Android to my local machine on a wifi network. My machines wifi ip address is 10.27.27.172 and I am running my node.js server on port 7890. I can use my phones chrome browser and browse to my server and access some endpoints which return json. My problem comes when I try and use spring-android rest template. I have given INTERNET permissions to my android application but I still get a ECONNREFUSED error. Is this an android port issue? Is the firewall blocking my request. If so why can I browse to the server but not use the REST client to get the information?
I found the answer on this stackoverflow. You need to make sure you retype the I guess the eclipse editor sometimes adds in invisible characters or something. Anyways it is working now.

SmartFoxServer unable to connect to server

I am working in android chat application.
I used SmartFox server. I am using 10.0.2.2 as server IP address and 9933 as Port.
Whenever i run this application using emulator then works fine but when i run this application in my real device then connection does not performed correctly. I think this is unable to find out IP 10.0.2.2.
I changed this IP address to 192.168.1.9 which is IP address of my system in LAN on which SmartFox server is installed.
Please suggest me what mistake i have done.
Thank you in advance.
I resolved my problem myself. I created one entry in confi/server.xml file of server.
like this:-
<serverSettings>
<socketAddresses>
<socket address="192.168.1.9" port="22" type="TCP"/>
<socket address="192.168.1.9" port="22" type="UDP"/>
</serverSettings>
</socketAddresses>
or you may add this entry using admin module of Smartfox server. This task can be done using Server configuration part.

Android HttpPost error java.net UnknownHostException

I have a java application trying to post to a php file on an IIS server and when I execute the post I get the java.net UnknownHostException. I have the set in the androidmanifet.xml right above the application element. Can somebody please help?
If your server is on a subnet, make sure you're including the full hostname in your HttpPost, e.g. barney.awesome.domain.com and not simply barney
I figured it out. Turns out the emulator that was started through eclipse would not connect to the internet. Had to manually start it up. Does anyone know why the emulator through eclipse does not connect to the internet?

Categories

Resources