-1

enter image description hereenter image description hereI am developing Android mobile application on Windows(OS). I want to send data to couchbase server. I am making mistake in URL for sync gateway. I am running services on my machine as well. I have already set up couchbase server.

My config.json file:

{
"log": ["HTTP+"],
"adminInterface": "127.0.0.1:4985",
"interface": "0.0.0.0:4984",
"databases": {
    "db": {
        "server": "http://localhost:8091",
        "bucket": "mobile_data",
        "users": {
            "GUEST": {"disabled": false, "admin_channels": ["*"] }
        }
    }
}
}

My Android App code:

private void initCouchbase() {


// Create replicators to push & pull changes to & from Sync Gateway.
        URL url = null;
        try {
            url = new URL("http://127.0.0.1:4984/db/");
        } catch (MalformedURLException e) {
        e.printStackTrace();
    }
    Replication push = database.createPushReplication(url);
    Replication pull = database.createPullReplication(url);
    push.setContinuous(true);
    pull.setContinuous(true);

 // Start replicators
    push.start();
    pull.start();
}

I am using my mobile for testing.

I am getting an error in connection with the URL.

Logcat:

01-28 19:21:23.851 28672-28718/com.example.yumnaasim.couchbaseapp W/RemoteRequest: com.couchbase.lite.replicator.RemoteRequest {GET, http://127.0.0.1:4984/db/_local/3259f53711e089457eaed7b5c61d82403d1a98e4}: executeRequest() Exception: java.net.ConnectException: Failed to connect to /127.0.0.1:4984.  url: http://127.0.0.1:4984/db/_local/3259f53711e089457eaed7b5c61d82403d1a98e4
                                                                               java.net.ConnectException: Failed to connect to /127.0.0.1:4984
                                                                                   at okhttp3.internal.io.RealConnection.connectSocket(RealConnection.java:187)
                                                                                   at okhttp3.internal.io.RealConnection.buildConnection(RealConnection.java:170)
                                                                                   at okhttp3.internal.io.RealConnection.connect(RealConnection.java:111)
                                                                                   at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:187)
                                                                                   at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:123)
                                                                                   at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:93)
                                                                                   at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:296)
                                                                                   at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
                                                                                   at okhttp3.RealCall.getResponse(RealCall.java:243)
                                                                                   at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201)
                                                                                   at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)
                                                                                   at okhttp3.RealCall.execute(RealCall.java:57)
                                                                                   at com.couchbase.lite.replicator.RemoteRequest.executeRequest(RemoteRequest.java:261)
                                                                                   at com.couchbase.lite.replicator.RemoteRequest.execute(RemoteRequest.java:165)
                                                                                   at com.couchbase.lite.replicator.RemoteRequest.run(RemoteRequest.java:105)
                                                                                   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
                                                                                   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
                                                                                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                                   at java.lang.Thread.run(Thread.java:818)
01-28 19:21:23.853 28672-28719/com.example.yumnaasim.couchbaseapp W/RemoteRequest: com.couchbase.lite.replicator.RemoteRequest {GET, http://127.0.0.1:4984/db/_local/3410a851b84016993416af638a20280537838364}: executeRequest() Exception: java.net.ConnectException: Failed to connect to /127.0.0.1:4984.  url: http://127.0.0.1:4984/db/_local/3410a851b84016993416af638a20280537838364
                                                                               java.net.ConnectException: Failed to connect to /127.0.0.1:4984
                                                                                   at okhttp3.internal.io.RealConnection.connectSocket(RealConnection.java:187)
                                                                                   at okhttp3.internal.io.RealConnection.buildConnection(RealConnection.java:170)
                                                                                   at okhttp3.internal.io.RealConnection.connect(RealConnection.java:111)
                                                                                   at okhttp3.internal.http.StreamAllocation.findConnection(StreamAllocation.java:187)
                                                                                   at okhttp3.internal.http.StreamAllocation.findHealthyConnection(StreamAllocation.java:123)
                                                                                   at okhttp3.internal.http.StreamAllocation.newStream(StreamAllocation.java:93)
                                                                                   at okhttp3.internal.http.HttpEngine.connect(HttpEngine.java:296)
                                                                                   at okhttp3.internal.http.HttpEngine.sendRequest(HttpEngine.java:248)
                                                                                   at okhttp3.RealCall.getResponse(RealCall.java:243)
                                                                                   at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:201)
                                                                                   at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:163)
                                                                                   at okhttp3.RealCall.execute(RealCall.java:57)
                                                                                   at com.couchbase.lite.replicator.RemoteRequest.executeRequest(RemoteRequest.java:261)
                                                                                   at com.couchbase.lite.replicator.RemoteRequest.execute(RemoteRequest.java:165)
                                                                                   at com.couchbase.lite.replicator.RemoteRequest.run(RemoteRequest.java:105)
                                                                                   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:423)
                                                                                   at java.util.concurrent.FutureTask.run(FutureTask.java:237)
                                                                                   at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:269)
                                                                                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
                                                                                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
                                                                                   at java.lang.Thread.run(Thread.java:818)
01-28 19:21:25.877 28450-28450/? I/Finsky: [1] com.google.android.finsky.scheduler.ak.a(146): onJobSchedulerWakeup

2 Answers2

2

The problem is with your Android app URL. You have http://127.0.0.1:4984/db/. This tries to connect to the Android device itself.

You need to have the external IP address of your server there instead. You configured Sync Gateway correctly with "interface": "0.0.0.0:4984". Beware, though, that you have guest access on ("GUEST": {"disabled": false, "admin_channels": ["*"] }, so you have no security as it stands.

Hod
  • 2,236
  • 1
  • 14
  • 22
0

You can reach on localhost with adb reverse port forwarding:

adb reverse tcp:4984 tcp:4984

After port forwarding, that is certain that you will encounter ssl problem. You have three options to solve this issue:

1- Add network security config for permit cleartext on localhost

2- Create and install custom ssl and push emulator/physical devices via adb

  • Every developer should install certificate to their machine, emulator and physical devices(Maybe scripting needed)
  • All service projects which used by Android should serve with ssl
  • Complexity

3- Permit cleartext globally while debugging

  • Quick to apply
  • You shouldn't forget in the prod environment.

Adb Extra:

If you have connected multiple devices, you can select device "-s {deviceId}" parameter For removing port forwarding, adb forward -remove tcp: {specifiedPort} or -remove-all

sermet
  • 422
  • 1
  • 8
  • 19