Sync gateway connection timeout

I am new to couchbase world. What is the URL should use to connect to my sync gateway on my development machine (not emulator) that I am debugging in?

I have tried, they either give timeout or connection refused error:
http://10.0.2.2:4984/sync_gateway/
http://10.0.2.2:4985/sync_gateway/
localhost:4984/sync_gateway/
localhost:4985/sync_gateway/
{{my actual IP}}:4984/sync_gateway/
{{my actual IP}}:4984/sync_gateway/

Background: I am trying to connection my android app (with couchbase-lite) to sync_gateway. I am running my app straight from android studio. The data gets stored locally in the device but how do I sync it with the sync gateway? This is the code that I have for initiation.

database = manager.getDatabase(dbname);
            //TODO: Only if the user is logged in
             URL url = new URL("http://10.0.0.6:4984/sync_gateway/");
            Replication push = database.createPushReplication(url);
            Replication pull = database.createPullReplication(url);
            pull.setContinuous(true);
            push.setContinuous(true);
//            BasicAuthenticator auth = new BasicAuthenticator(USERNAME, PASSWORD);
//            push.setAuthenticator(auth);
//            pull.setAuthenticator(auth);

            push.addChangeListener(new Replication.ChangeListener() {
                @Override
                public void changed(Replication.ChangeEvent event) {
                    Toast toast = Toast.makeText(DataService.context, "Push:" + event.getError().getMessage(), Toast.LENGTH_SHORT);
                    toast.show();

                }
            });
            pull.addChangeListener(new Replication.ChangeListener() {
                @Override
                public void changed(Replication.ChangeEvent event) {
                    Toast toast = Toast.makeText(DataService.context, "Pull:" + event.getError().getMessage(), Toast.LENGTH_SHORT);
                    toast.show();
                }
            });
            push.start();
            pull.start();

My sync gateway configuratoin is:

{
  "interface":":4984",
  "adminInterface":":4985",
  "log": ["CRUD", "REST+", "Access"],
  "facebook": {"register": false},
  "databases":{
    "sync_gateway":{
      "server":"http://localhost:8091",
      "bucket":"sync_gateway",
      "users": {
        "GUEST": {"disabled": false}
      },
      "sync":`function(doc) {channel(doc.channels);}`
}
}
}

Whats am I doing wrong?

Hi @hadesara,

You can try accessing {{my actual IP}}:4984/sync_gateway/ in the browser of the android device to test the url.
If it’s up, then there’s something with the replication code in the app.

Can you see things happening in the SG logs?
Are exceptions thrown in the Android debugger?

Thanks
James

Hi,

I’m having the same issue with setting up sync gateway on an Amazon EC2 Windows instance. Whenever I attempt to connect to the sync gateway from anywhere other than localhost I get a connection refused error. I have checked that both ports 4984 and 4985 are open both in the Amazon security group as well as in the Windows firewall. The server was started using default settings

sync_gateway -url http://localhost:8091

I do not see any activity or errors on the server when making these requests unless they are made from the local machine using

http://localhost:4984/sync_gateway/

which succesfully returns a JSON response containing information about the server.

If it is relevant, I am making these requests through a web browser as for now I am only interested in whether I have configured everything properly. Any help would be very much appreciated.

@mcarino

You could try and start sync gateway with the ports bound to all interfaces:

sync_gateway -url http://localhost:8091 -adminInterface 0.0.0.0:4985 -interface 0.0.0.0:4984

If that solves your issue, you can then change the public REST interface IP address to bind to the specific public interface of your AWS instances. You would want to limit access to the admin interface, so you could either bind that to localhost (127.0.0.1) or to the private IP address of your AWS instance.

Andy

Hey there, I have recently started working on Couchbase and its feature. I was trying to connect to Sync_Gateway through the URL mentioned got the same kinda issue you stated above. Seems you got the issue quite earlier, did you got the solution?

@sutrishna30

Did you try the solution posted above of binding the Sync Gateway ports to all network interfaces?

By default Sync Gateway only binds to the local loopback interface.

Thanx Andy for your quick response.
i did tried binding the ports with command given but the issue seems associated with port listening.

It does shows Starting Server… but doesnot result connecting and later it needs to break it there.

@sutrishna30

The command you show above binds the interfaces to 127.0.0.1, the local loopback address, you will not be able to connect to Sync Gateway from another host with that config.

To prove that connectivity is working change your binding address to 0.0.0.0, this will allow connections from all hosts.

I did tried with 0.0.0.0 but gives the error below in screenshot.

I have installed Sync_Gateway 1.3.1 Enterprise version. I was just wondering if this is because of any compatibility issue of this version with Windows. Or is it like we need to install first the basic 1.3.0 version and then do upgrade it to 1.3.1.

It looks like you have used the same port for admin and public rest apis, try using port 4984 for the public api.

Get Outlook for iOShttps://aka.ms/o0ukef

Sorry Andy. Guess I took the wrong screenshot. I did tried with 4984 port but it gives the starting status but doesnot get connected.
Few points I want to mention:-

  1. My Couchbase server and CB Sync gateway are both installed in same system. Shall it be on different machines?
  2. When I am doing netstat -n, I cant find 4985 and 4984 listed. So does these 2 ports require to be opened separately as, as per site, installation of sync_gateway should by default do that?
    3.I have installed Sync_Gateway 1.3.1 Enterprise version. I was just wondering if this is because of any compatibility issue of this version with Windows. Or is it like we need to install first the basic 1.3.0 version and then do upgrade it to 1.3.1.