Connect to GlassFish server using HttpURLConnection in Android - android

I am developing an Android application that accesses a remote server using HttpURLConnection.
The server was (and still is) developed using NetBeans so, when testing the server on my local machine, I run it using NetBeans and the built-in GlassFish server.
I have tried to connect to the running server in Eclipse using HttpURLConnection giving localhost as the server (with the socket) but keep getting Connection Refused.
I can still access the local server from my browser with no problem but can't get to it from Eclipse.
The code also works when copnnecting to the actual remote server.
I am not sure where to go next.

if i remember correctly, 10.0.2.2 is the IP Address you need for the app on the emulator to talk to your development machine. Yep. see http://developer.android.com/tools/devices/emulator.html ("Network Address Space")

Related

API Calls connecting to intranet server not working in Android Emulator

I am trying to connect to the local intranet server from my android application. The api calls work fine in the postman and other clients. But, when I am trying to do the get or post request to the server from android emulator, it's returning response code "503" (meaning host is not reachable).
The APIs are hosted in the server system which is in the local network. I have tried adding proxy, DNS settings, still no use.
I am stuck on this issue since a week now.
It would be great if someone could help on this!
you need to set URL as 10.0.2.2:portNr
portNr = the given port by ASP.NET Development Server

How to connect to cakephp server with localhost:port from Android emulator?

I am running the cakephp built in server bin/cake server which works fine for making requests through my laptop's browser: localhost:8765/users/get/1.
Yet when I try through my Android emulator to reach 10.0.2.2:8765/users/get/1 it just returns 10.0.2.2 refused to connect.
If I turn off the cakephp server and use MAMP instead I can successfully reach my local server with 10.0.2.2:8888/ionic-backend/users/get/1. So I know my emulator is setup correctly but does anyone know how to connect using cakephp's server? It would be much more convenient.
I am using a Mac, if that helps.

Android Emulator: can't connect to server

I'm newbie in Android development so forgive me for a banal question
I'm in this situation: I have a server locate on IP address 192.168.11.188; this server sends a JMS message by using MQTT protocol
On my laptop I'm using paho as MQTT messages consumer
I'm building an Android app and I test it by using the emulator
I have the following problem: if i test everything in local by configuring the APP to connect to the JMS server on my laptop and specifying the IP address 10.0.2.2 all works pretty good
When i configure the APP in order to connect to the server on IP address 192.168.11.188 it can't connect (I tried by using telnet and I can confirm that server is alive and active)
Moreover in the sent MQTT message I have a URL that points to a my site. The URL is like: http://192.168.11.188:8080/.....
Well inside the emulator i can't open the URL; I get the error "net::ERR_CONNECTION_REFUSED" (but I'm sure the server is active)
I attach an image showing the error
I'm struggling on this problem from some days...
I'm sure I'm missing something but I can't figure what I'm missing
How can I configure correctly the emulator in order to connect to the server on the the IP 192.168.11.188 and open web pages always from this IP?
thank you
Angelo

Android:Socket programming between phone and system

I am trying to write a client server application, in which the client is a android device.
I am not confident on socket programming.
I have written a server side application and a client side that runs on my emulator.
Will the same application work between a real android device?
I have edited your question (once its reviewed it will show up). From what I understand, your question is generic. It works on my emulator, will it work on my device.
The answer is yes. The emulator connects to 10.0.2.2 which redirects to 127.0.0.1 on your host machine right ? This is how you would have got it working.
To get it working from a device you will need to do the following
Load your java server on your real ip address on your desktop
Ensure that your desktop is on the internet and the ip address visible to the internet (open)
Ensure that your android phone points to the public ip address of your desktop.
Now, I know your worry :) open ip address. So, you can use a ec2 (free amazon ubuntu instance), install java on it and run your server as java -jar . From eclipse you can export a jar file (runnable jar file) with lib in your jarfilename_lib path.
You can use spring For android via HTTP request.
Here is an example.
When you have static ip in server you should set that static ip in your actual device.If you are running your app on emulator you must set 10.0.0.2.

How do you call remote servlet from android client?

I have developed android client which calls tomcat servlet which is on same PC. It runs fine.
I've used url
http://10.0.2.2:8080/servletname
to call servlet and its working properly. Now i want to keep android client on one PC and Tomcat server on other. How should i proceed?
I have connected two laptops using LAN cable. I'm unable to configure all settings and permissions to call remote tomcat server.
Can anyone please tell me, how should i properly configure network ?
Now i want to keep android client on one PC and Tomcat server on other. How should i proceed?
Use the IP address of your Tomcat server.

Categories

Resources