My app is working fine in AVD but when i try to run my app in my mobile it is showing this error. It is not connecting to server. It is not accessing php file. I have given path for php file is "http://10.0.0.72/myapp/search.php". I'm using wamp server and kept my php file inside www folder.
Logcat Error
java.net.ConnectException: failed to connect to /10.0.0.72 (port 80):
connect failed: ETIMEDOUT (Connection timed out) 06-13 13:19:20.229
13823-14092/com.myapp W/System.err: at
libcore.io.IoBridge.connect(IoBridge.java:114)
Caused by: libcore.io.ErrnoException: connect failed: ETIMEDOUT (Connection timed out)
I assume that you run your wamp server in local PC. Connect both your phone and PC (which has the wamp server) to the same network and replace 10.0.0.72 with the private IP of the PC.
Try the url in the phone browser, It should be accessible.
Make sure you have given internet permission in the manifest file.
Related
The error that I am getting is
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN, servers=[{address=localhost:27017, type=UNKNOWN, state=CONNECTING, exception={com.mongodb.MongoSocketOpenException: Exception opening socket}, caused by {java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 27017) from /127.0.0.1 (port 43950) after 10000ms: isConnected failed: ECONNREFUSED (Connection refused)}, caused by {android.system.ErrnoException: isConnected failed: ECONNREFUSED (Connection refused)}}]
I'm assuming the issue here is that the AVD is using the same IP as my computer, but if I try to change it in the settings of the AVD it fails to connect to androidWifi. (I tried changing it to 10.0.2.2, because that's the solution I found on annother stackoverflow post, it didn't work.)
If it matters, my code looks like this:
MongoClient client = MongoClients.create("mongodb://localhost:27017");
MongoDatabase db = client.getDatabase("userData");
MongoCollection<Document> users = db.getCollection("users");
Document user = new Document("name", "user").append("password", "pass");
users.insertOne(user);
Adding this answer for posterity - the reason why this error occurs is because in the line:
MongoClient client = MongoClients.create("mongodb://localhost:27017");
the DB address is being set to the ANDROID'S localhost and NOT the PC's that's hosting the AVD. To fix this, find your ipv4 address using the command ipconfig
in CMD, then, when running the mongo shell type the following command: mongod --bind_ip "yourIPHere"
please do note, however that this will open your database up to external connections, if someone happens to have your internal IP address.
I am trying to trace a request originating from android and send some data to serversocket at each hop. I am using below code to execute client and send data to ServerSocket at each hop (tomcats having servlet projects) and they are able to send and connect.
However when I try to use same below code in android app running on emulator on same machine. It throws me timeout error.
InetSocketAddress hostAddress = new InetSocketAddress(hostAdress,
SocketServerPORT);
SocketChannel client = SocketChannel.open(hostAddress);
after open execution gives me
java.net.ConnectException: failed to connect to /192.168.0.102 (port 8090): connect failed: ETIMEDOUT (Connection timed out)
01-24 13:25:58.140 3382-3424/app W/System.err: at libcore.io.IoBridge.connect(IoBridge.java:124)
01-24 13:25:58.140 3382-3424/app W/System.err: at libcore.io.IoBridge.connect(IoBridge.java:110)
01-24 13:25:58.140 3382-3424/app W/System.err: .....
what could possibly be wrong here?
my app has
<uses-permission android:name="android.permission.INTERNET" />.
I have also used
Socket socket = new Socket(hostaddress,port)
It throws same exception.
I have connected my Android App to WAMP server and I am running it on my mobile phone but each time I run the app, it gives the error:
Exception: failed to connect to /192.168.1.5 (port 9090): connect
failed: ETIMEDOUT (Connection timed out)
I am giving this URL:
String url = "http://192.168.1.5:9090/phpmysql.php";
Can anyone tell me what am I doing wrong? I saw this link too but wasn't much helpful.
Use 10.0.2.2 for emulator.
I think the url you are using is creating problems.
If it doesn't fix this error, try resetting the adb connection by force closing it from task manager and restarting the emulator. Also the wamp server should be running and should be accessible from your local browser.
When I try to run my android app, I following error:
"java.net.UnknownHostException: Unable to resolve host "www.omdapi.com": No address associated with hostname".
The URL I'm contacting is correct. I have tried restarting wifi on my phone which is connected to the computer when I run my app, I have tried 4G instead of WiFi, and I have tried restarting my computer. But it still shows this long error: http://pastebin.com/LZsc2w45
Do anyone know what's wrong?
I am getting this error while trying to send mail through java mail. It used to work for me, but recently I switched to jdk7 and glassfish 3.1.2. I tried to switch it back to jdk6 also but it's not working anymore, here is the error I'm getting:
javax.mail.MessagingException: Could not connect to SMTP host: smtp.illumina.com, port: 25;
nested exception is:
java.net.SocketException: Permission denied: connect
Telnet and ping to this server is fine. Its working from other systems. Only my local setup is throwing this error.
Any ideas?