0

I fired up a new ROS on a Google Cloud Compute ubuntu vm and am trying to write objects via a Xamarin.Android project:

public class TestObject : RealmObject
{
    public string TestString { get; set; }
    public int TestInt { get; set; }
}

//new non-existent realm, I also tried a public realm -> realm://###.###.###.###/newrealm
var realmUrl = "realm://###.###.###.###/~/newrealm";

//preconfigured admin credentials
var creds = Credentials.UsernamePassword("admin@gmail.com", "password", false);
var user = await User.LoginAsync(creds, new Uri("http://###.###.###.###:9080"));
var config = new SyncConfiguration(user, new Uri(realmUrl));
var realm = Realm.GetInstance(config);

//this event never fires
Session.Error += (sender, errorArgs) => { var ex = errorArgs.Exception; };

//left this in just to be sure there were no permissions issues
await user.ApplyPermissionsAsync(PermissionCondition.Default, realmUrl, AccessLevel.Write);

//this will contain objects on subsequent runs
var existing = realm.All<TestObject>().ToList();

//also tried realm.Write(() => { });
using (var trans = realm.BeginWrite())
{
    var test = new TestObject();
    test.TestString = "test";
    test.TestInt = 99;
    realm.Add(test);
    trans.Commit();
};

The result is that the new realm is created successfully on the remote ROS, but it remains empty according to the dashboard and the Realm Browser even after multiple runs of this code. You'll notice in my comment that the local realm does contain the written objects, just not the remote. The server logs show a lot of messages when this code is executed, but there are no warnings or errors. What have I missed?

  • Can you try adding `await realm.GetSession().WaitForUploadAsync()` - upon completion, the local data will have been synced with the Realm Object Server. Here's the docs: https://realm.io/docs/xamarin/1.6.0/api/reference/Realms.Sync.Session.html#Realms_Sync_Session_WaitForUploadAsync – Nikola Irinchev Aug 30 '17 at 11:32
  • @NikolaIrinchev the code doesn't seem to ever progress past WaitForUploadAsync. Break points don't hit and System.Diagnostic.Debug.WriteLine calls don't print. Still no errors in any try/catch block or Session.Error. I experience this behavior if I place this call before even writing anything to the realm. Application output:[Mono] DllImport searching in: 'realm-wrappers' ('librealm-wrappers.so'). [Mono] Searching for 'realm_syncsession_wait'. [Mono] Probing 'realm_syncsession_wait'. [Mono] Found as 'realm_syncsession_wait'. [Mono] [0x96d92930] worker unparking, timeout? no interrupted? no – aweFalafelApps Aug 30 '17 at 13:55
  • Hm... another question, your `realmUrl` seems to lack the port in the snippet you posted - is this the case in your app, or just an oversight when pasting code on SO? If that's the case, then you need the port like `realm://###.###.###.###:9080/~/newrealm` – Nikola Irinchev Aug 30 '17 at 19:25
  • @NikolaIrinchev thank you so much for taking the time to help! – aweFalafelApps Aug 30 '17 at 19:51

1 Answers1

1

Thanks to Nikola for figuring out I was missing the port number on the realm url. After adding it, everything seems to be working correctly.

var realmUrl = "realm://###.###.###.###:9080/~/newrealm";

Seems odd that no errors of any kind were thrown, objects were just silently not written to the remote realm.

  • Glad to have helped! To elaborate on the lack of errors, the Realm Mobile Platform is designed to work well when the device is offline. In this case, when it is unable to connect to the server, it assumes it is offline or the server is unreachable for some reason (e.g. proxy or other network problems). So it stores the data locally and whenever connectivity is restored, it'll upload everything. – Nikola Irinchev Aug 30 '17 at 20:03
  • Would perhaps be possible to at least show some diagnostic output when a network connection is present, but a connection to the remote realm cannot be made? – aweFalafelApps Aug 30 '17 at 21:16