Search code examples
androidsymmetricds

SymmetricDS Android demos both register but do not sync


(x-post from SymmetricDS forum)

Do you have a working example of using SymmetricDS 3.8 to sync an Android application with a demo root node? I've worked through both of JumpMind's examples, and both fail with ECONNREFUSED against localhost:31415.

It looks like even though they know how to register with the root node on a different machine, they try to sync with it on localhost instead.

Here's a walkthrough of how to build and (unsuccessfully) run both of the existing samples.

Sample 1:

Jumpmind's original demo from 2012 used the Notepad Application, and many of the steps assume you're running in Eclipse and have their Pro version. There are a few hoops to make it compile in a modern Android Studio with the freeware version of SymmetricDS.

  • in Studio, New Project -> Import from Android/Sdk/samples/android-23/legacy/NotePad
  • do a test compile and run to make sure it works unmodified
  • download and extract sample 2 to get the libs
  • extract the libs into Notepad/app/libs/
  • edit your apps gradle rule, add a compile dependency, thus:

    dependencies { compile fileTree(dir: 'libs', include: '*.jar') }

  • gradle sync
  • paste the recommended code from the tutorial into the second OnCreate in NotePadProvider.java.(the first one is in a static class DatabaseHelper)
  • modify REGISTRATION_URL to point to your root node
  • modify NODE_GROUP_ID appropriately. If you're using the demo server, this should be "store".
  • I used an external ID of "android-003", because that's what's used in sample #2.
  • Don't forget to open registration for your external ID. Something like

    symadmin --properties corp-000.properties open-registration store android-003

  • observe the logcat failure

    Building transport url: http://localhost:31415/sync/corp-000/push?nodeId=android-003&securityToken=88b79dcc9617099aec015ae5ed800b&hostName=localhost&ipAddress=10.0.2.15 Could not communicate with node 'corp:000:000' at http://localhost:31415/sync/corp-000 because of unexpected error org.jumpmind.exception.IoException: java.net.ConnectException: failed to connect to localhost/127.0.0.1 (port 31415) after 20000ms: isConnected failed: ECONNREFUSED

Sample 2:

Jumpmind's newer sample includes support for file sync, which I don't care about right now. But it's supposed to work against the demo node corp-000 right out of the box. At least for me, it doesn't.

Here's what you have to do:

  • download the source
  • modify REGISTRATION_URL (to use the dev machine's non-localhost IP address)
  • modify the manifest as described in the tutorial
  • attempting to run the app will fail with INSTALL_FAILED_CONFLICTING_PROVIDER, I had to change the provider defined in the manifest to com.jumpmind.syncds3.DbProvider, because there's already an app on the default Android image that uses provider com.google.provider.NotePad.
  • open registration for android-003 on the server / root-node
  • confirm registration by looking in the server's sym_node_security table.
  • Interestingly, there is no initial_load_time in that row, and it shows no sign of syncing.
  • Back in your Android app, observe the same logcat errors attempting to sync against a corp-000 node on localhost.

Solution

  • Solved. For anyone coming this way with a similar problem, the problem is twofold.

    1. The client gets its sync url from the server. The demo server specifies a sync-url on localhost.
    2. The (bad) sync URL persists in the sym tables, apparently on both the client and the server.

    Solution:

    If you're running on Linux, feel free to use my scripted demo server. It sets sync-url to the first IP address in the list instead of localhost.

    Otherwise:

    1. Stop your client and server.
    2. The demo root node is configured with a SYNC URL on localhost in corp-000.properties. This is the source of your problem. Change it to a meaningful IP address. Use a non-standard port too, to help illustrate the problem -- this will mean adding a --port xxxx to the command you use to run the root node.
    3. Delete and recreate your root node database. I'm not sure what was stale in here, but re-running the server on a new address didn't seem to suffice. There might be another way to refresh this, but starting over is easiest.
    4. Delete your android node database. I used "adb shell rm -rf /data/data/com.jumpmind.*"
    5. Re-run your server and client.