Connecting android/ios device to Local Sync Gateway

Hello Team,

I am working android app which is already developed with Couchbase integration and I’m new to Couchbase. The app is working fine.
But I want to support local sync gateway for the app. I have successfully deployed SG on a local server using docker. I see data getting sync on Android EMULATOR but the same app is not working on an actual device when app pointing to local SG.
My sync gateway URL - “ws://10.0.2.2:4985/db_name”

Also important, I am on a VPN and I have to use it. And both my machine and device are on the same network.

I tried getting an actual IP address from a device after connecting to a VPN. and use like this “ws://<ip_address>:4985/db_name”

I am getting the following error

`E: CBLWebSocket.socket_open()

E: {N8litecore4repl12C4SocketImplE#3}==> N8litecore4repl12C4SocketImplE ws://<ip_address>:4985/db_name/_blipsync
E: {N8litecore4repl12C4SocketImplE#3} No response received after 15 sec – disconnecting
E: TransactionStateUtil: Attempting to convert network exception java.net.ConnectException to error code.
E: {Repl#4}==> N8litecore4repl10ReplicatorE /data/user/0/com.example.test/files/test.cblite2/ ->ws://<ip_sddress>:4985/db_name/_blipsync
E: {Repl#4} Got LiteCore error: POSIX error 110 “Connection timed out”
E: CBLWebSocket.socket_open()
E: Cannot contact service to set scan periods
E: {N8litecore4repl12C4SocketImplE#5}==> N8litecore4repl12C4SocketImplE ws://<ip_address>:4985/db_name/_blipsync @0x55a6c4f180
E: {N8litecore4repl12C4SocketImplE#5} No response received after 15 sec – disconnecting`

I just want my App to get synced with the local Sync Gateway from the actual device. Please help me with this.

This is not a real URL. This is just the “magic Android emulator” URL for localhost on the machine running the emulator. To connect to Sync Gateway you need to use the actual accessible IP address of the machine running Sync Gateway. If you cannot get a connection, then confirm you can connect via browser to http://<ip_address>:4984 (don’t use 4985). If you can’t then you have a network issue, try disabling your firewalls as a test, etc.

1 Like

Thank you so much @borrrden :+1: :smiley:

Your suggestion worked for me. Without a VPN app getting synced with the local SG server on an actual device.
I would like to know if I can do the same while connecting to a VPN? I tried with a VPN it did not work. Is there any solution for this?

“I tried it and it did not work” is not a problem description, and therefore cannot have a solution. Nothing I can think of would prevent such a scenario since all of that is a level removed from Couchbase Lite.