Couchbase Lite Mobile peer-to-peer replication

I want to try out the Couchbase Mobile peer-to-peer replication functionality.

From, “Supports peer-to-peer replication. By adding an extra HTTP listener component, your app can accept connections from other devices running Couchbase Lite and exchange data with them.”

From, “Couchbase Lite can replicate with another instance of itself, if the other instance includes the optional Listener component and is listening on a TCP port.”

Unfortunately, I have looked through the documentation and forums, and can’t any further information on this.

  1. Is this functionality supported on Android?
  2. Is there any other documentation which details how this peer-to-peer replication can be implemented? Sample code would be very useful.
1 Like

Yes, the listener is included on Android. The Jar should be part of the download. You use it to open a listening port that can serve the replication API. Then another device can use your device’s IP address and the port number to construct a replication URL like and replicate with it. That’s about all there is to it. We don’t have explicit sample code.

Thank you for the above.

A device A is using the couchbase-lite-java-listener library to create an instance of LiteListener and open a listening port. In the emulator, the couchbase URL can be accessed via http://

A device B is acting as a peer device and is replicating couchbase on device A. In the emulator, the couchbase URL can be accessed via http://

In order to interconnect the different emulators, I added the necessary network redirection rules to forward traffic from the localhost to the server port.

However, when I try to start replication from device B, I get the following error (device B):
Got error status 404 for Reason: Not found

The error on Device A states:
Router unable to route request to do_GET_Document_session

There is a connection between the devices as I can connect on both devices to the replication URL via a browser. Authentication details are also correct - I am using BasicAuthenticator for this. The couchbase-lite-android and couchbase-lite-java-listener libraries for both projects were updated to version 1.0.4, as some blog posts attributed this issue to lower versions of the libraries.

What can be the cause of these errors?

Sounds like a bug in the HTTP listener on device A. Are those both Android? I don’t work on the Android version; I’ll bring this to the attention of the people who do.

Yes, both devices are Android. The listener library is couchbase-lite-java-listener.

If this is a bug, would you have any visibility on whether this would be fixed and delivered in the foreseeable future?

Yes, this will be looked at soon.

Just run a quick check from an emulator’s browser.

Env: A listener running on port 10000. A redirection is set as redir add tcp:5000:10000
Test URL:
Result: {“error”:“not_found”,“reason”:“Router unable to route request to do_GET_Document_session”}

From the result, the router class doesn’t route ‘_session’ request correctly.

I created a new ticket for this issue:

1 Like

Have you solve this problem? I also really interested in peer-to-peer replication on Android.

As many community developers are interested in peer-to-peer feature, we will investigate this issue as soon as possible. Thank you very much for your patience.


Excuse me for giving you so much trouble, thanks.

Pending the resolution of the authentication issue, will the replication require the use of the sync_gateway, or is it enough to directly call the Couchbase server URL served on a Device A and use this as the replication URL?

Once that bug is fixed, P2P replication should work. You just determine the IP address/port the other peer is listening on, and the database name, and use the corresponding URL as the “server” URL to replicate with.

In your initial example, device B would replicate with, i.e. the URL device A is serving.

The bug has been fixed, and replication seems to be working fine now; I no longer get the error 404 not found.

Do you have some ideas that how to replication over the internet. It is not difficult in LAN, but I have no idea over the internet. There are some problems, such as NAT.

Maybe look into setting up a STUN server to do NAT traversal (similar to how WebRTC does it). Twillio provides some for free

P2P messaging over the Internet is a huge topic that we can’t really answer here. There are all sort of issues like reachability, discovery, fault-tolerance, security… We’re not providing solutions to those, at least not yet.