1

I am trying to sync my android application with the sync server, but the client doesn't seem to be able to connect to the server. The Admin UI is running perfectly on localhost:9980. The server is running on docker.

001-13:29:41.2231 [INFO ] [SvrUws] UwsServer listening on all interfaces, port 9999 without SSL
001-13:29:41.2234 [WARN ] [SvSync] UNSECURED no-authentication mode enabled - every client allowed without any validation
001-13:29:41.2256 [INFO ] [SvSync] Started on port 9999
001-13:29:41.2257 [INFO ] [SySvAp] Starting object browser on 0.0.0.0:9980
001-13:29:41.2263 [INFO ] [HttpSv] Running in single-store mode with an already opened store
001-13:29:41.2263 [INFO ] [HttpSv] Listening on 0.0.0.0:9980
001-13:29:41.2266 [WARN ] [HttpSv] UNSECURED no-authentication mode enabled:
!!! Allowing access to anyone without any user validation
!!! After e.g. adjusting user logins, please restart asap to secure the server again
001-13:29:41.2266 [INFO ] [HttpSv] User management: enabled
001-13:29:41.2305 [INFO ] [HttpSv] HttpServer listening on all interfaces, port 9980
001-13:29:41.2318 [INFO ] [SySvAp] ObjectBox sync server started in 62 ms

enter image description here

First I tried what the docs say "wss://127.0.0.1", then I tried with ws, then with the port number specified (both 9980 and 9999). Then I tried to configure the url.

{
    "dbDirectory": "objectbox",
    "bind": "ws://0.0.0.0:9999",
    "browserBind": "http://127.0.0.1:9980",
    "browserThreads": 4,
    "certificatePath": ""
}

None of it worked. Please help me how to find the correct address to connect.

UPDATE: In emulators you have to use 10.0.2.2 to reach localhost! In the MainActivity onCreate() method:

BoxStore boxStore = ObjectBox.get();

        SyncClient syncClient = Sync.client(
                boxStore,
                "ws://10.0.2.2", 
                SyncCredentials.none()
        ).buildAndStart();

enter image description here

Menci
  • 73
  • 7

2 Answers2

1

You need to specify the IP of the machine running the server.

In case you are running an Android emulator, use 10.0.2.2 to reach the host.

This would be a good addition to the Sync troubleshooting guide actually... Updated, thanks.

Markus Junginger
  • 6,950
  • 31
  • 52
  • I am running an emulator,Yes I also tried with 10.0.2.2 but it didn't work. – Menci Sep 27 '21 at 16:23
  • From inside the emulator, please start the browser app and enter http://10.0.2.2:9980 - do you see the ObjectBox admin web app? – Markus Junginger Sep 28 '21 at 06:08
  • Yes, I see it . – Menci Sep 28 '21 at 15:22
  • 1
    Great. Next, in the admin interface, enable Debug logs (see https://sync.objectbox.io/objectbox-sync-server#status) and check the server's output. When the client tries to connect, you should see some info, e.g. an error why it's declined. If you do not see anything, you still have a network problem. Then, try to reach the server using the 9999 port in the browser; there you should see some short text when the connection is good. – Markus Junginger Oct 07 '21 at 06:49
  • I don't have that option in the admin interface. I posted a picture of my admin UI above. If I go to port 9999 in the browser I see a "Hello HTTP request" message, so probably the problem is not with the network. – Menci Oct 08 '21 at 08:40
  • I managed to solve the problem! I needed to add a few permission to the android application. I should have think about it sooner, but still it would be great if the docs would have a reminder of this, it cost me a week : D – Menci Oct 08 '21 at 09:19
1

SOLVED!

The android application was missing these permissions:

<uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

After adding these, everything worked fine!

Menci
  • 73
  • 7
  • 1
    If your project does not otherwise needed, it's fine to remove the `ACCESS_WIFI_STATE` permission. `ACCESS_NETWORK_STATE` is enough for ObjectBox to detect network changes. – Uwe - ObjectBox Oct 11 '21 at 12:39