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.
Related
java.sql.SQLNonTransientConnectionException: Could not connect to address=(host=localhost)(port=3306)(type=master) : Socket fail to connect to host:localhost, port:3306. Connection refused
tried: adding this bind-address = ::
tried changing from localhost too xxx.xx.xx.....
Help. thank you
i'm trying to connect local java app to openshift MongoDB using this code
String mongoUri = "mongodb://admin:password#myServerIP:27017/";
MongoClient mongoClient;
mongoClient = new MongoClient(new MongoClientURI(mongoUri));
DB db = mongoClient.getDB("mongo");
System.out.println("Successfully connected to MongoDB ");
but it connect to local machine MongDB ? it give me this error ?
com.mongodb.MongoTimeoutException: Timed out after 10000 ms while waiting for a server that matches AnyServerSelector{}. Client view of cluster state is {type=Unknown, servers=[{address=remoteIpAddress:27017, type=Unknown, state=Connecting, exception={com.mongodb.MongoException$Network: Exception opening the socket}, caused by {java.net.ConnectException: Connection refused: connect}}]
i'm search and i found solution (port forward) but i can't do it , any one give me solution , thanks .
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.
My server's code looks like:
Registry r = java.rmi.registry.LocateRegistry.createRegistry(1399);
r.rebind("Chat", new IRC());
and my client's code is
IRCInterface remoteObject = (IRCInterface) Naming.lookup("rmi://localhost:1399/Chat");
String history = remoteObject.read();
on the localhost it works correctly, but I can't connect two remote computers (hosts).
I've turned off all firewalls.
What's wrong?
The console outputs:
Error: java.rmi.ConnectException: Connection refused to host: 150.254.79.20; nested exception is:
java.net.ConnectException: Connection timed out: connect
Naming.lookup("rmi://localhost:1399/Chat");
localhost in above lookup should be replaced with remotehost IP (or) machine name. Otherwise lookup happens on only local machine.
I should be able to successfully send and receive file to/from FTP server.
But then, no changes occurred in the code and I started getting this :
Error: java.net.ConnectException: Connection timed out: connect
What I am doing is:
FTPClient ftp = new FTPClient();
ftp.connect( IPADDRESS of FTP server);
connect() is giving this execption. I am not understanding the cause for it.
The error message is telling you that the OS's attempt to connect to the server timed out. This typically means that:
the remote server has dropped off the network, or
something (e.g. a firewall) is "black holing" packets sent to the server on the FTP port.
Signals that an error occurred while attempting to connect a socket to a remote address and port. Typically, the connection was refused remotely (e.g., no process is listening on the remote address/port).
Source: JavaDoc.