如何使用同步网关将数据发送到couchbase服务器,如何连接到同步网关,URL?

时间:2018-01-28 14:25:20

标签: couchbase couchbase-lite

enter image description here enter image description here我正在Windows(OS)上开发Android移动应用程序。我想将数据发送到couchbase服务器。 我在同步网关的URL中犯了错误。我也在我的机器上运行服务。我已经设置了couchbase服务器。

我的config.json文件:

{
"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": ["*"] }
        }
    }
}
}

我的Android应用代码:

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();
}

我正在使用手机进行测试。

我收到与网址相关的错误。

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

1 个答案:

答案 0 :(得分:2)

问题在于您的Android应用网址。你有http://127.0.0.1:4984/db/。这会尝试连接到Android设备本身。

您需要在那里拥有服务器的外部IP地址。您使用"interface": "0.0.0.0:4984"正确配置了同步网关。但要注意,您可以访问("GUEST": {"disabled": false, "admin_channels": ["*"] }访客,因此您没有安全保障。