Anantha Raman
Anantha Raman

Reputation: 197

java.net.ConnectException: Failed to connect to /127.0.0.1:9080 realm Object server

I just installed realm object server after seeing the documentation in the website.I created a login page (android) and i used syncronised user settings as per the website. but my asynctask on create shows the above error. Here is my code :

public class RealAsyncTask extends AsyncTask<String, Void, String> {

Realm realm;
String url = "http://127.0.0.1:9080";
long schemaVersion = 001;

@Override
protected String doInBackground(String... strings) {
    try {
        SyncCredentials syncCredentials = SyncCredentials.usernamePassword("realm-admin", "", true);
        SyncUser user = SyncUser.login(syncCredentials, serverUrl());
        SyncConfiguration config = new SyncConfiguration.Builder(user, realmUrl())
                .schemaVersion(schemaVersion)
                .build();
        realm.setDefaultConfiguration(config);
    }
    catch (Exception e){
        e.getCause();
    }
    return null;
}

private String realmUrl() {
    return url;
}

private String serverUrl() {
    return url;
}
}

I am deploying my application in my mobile and while debugging i got the above error message. Thanks in advance for the help.

Upvotes: 2

Views: 4053

Answers (1)

Tomin B Azhakathu
Tomin B Azhakathu

Reputation: 2686

Connect the server and mobile on the same network or host the server in web server.

Use server system's IP Address instead of 127.0.0.1.

Use IP 10.0.2.2 if you are using an Emulator.

Every system itself is a localhost so when you call 127.0.0.1 the system calls itself.

Upvotes: 3

Related Questions