【问题标题】:How to write to a Realm object server on Ubuntu如何在 Ubuntu 上写入 Realm 对象服务器
【发布时间】:2016-10-29 02:20:29
【问题描述】:

我已经完成了 Realm 移动平台教程 (link)。您创建一个 Swift 任务应用程序。

我能够让应用程序和服务器在我的本地 Mac 上正常工作。我能够向 tableview 添加任务。

然后我在 DigitalOcean 上创建了一个 Ubuntu 16.04 droplet。我设法让服务器运行并能够查看 Realm 仪表板。

问题是,当我使用新的服务器 IP 地址(ubuntu 实例)运行应用程序时,我看到“添加任务”弹出,但没有任务被添加到应用程序的表视图中。

以下代码将任务添加到数据库中:

try! items.realm?.write {
 items.insert(Task(value: ["text": text]), at: items.filter("completed = false").count)
}

当我在本地机器上运行代码时,它会插入值,但当我使用远程服务器时,insert 行永远不会被命中。

这是我将 Realm 配置设置为新 url 的地方:

let configuration = Realm.Configuration(
                syncConfiguration: (user, URL(string: "realm://128.199.119.xxx:9080/~/realmtasks")!)
        )

当您将 Realm configuration.yml 文件部署到远程服务器时,您是否必须更新它?如果是,是否有人有 configuration.yml 示例或需要做什么来设置文件?

在教程视频中提到 info.plist 需要更新。对于访问已部署服务器的应用或应用商店中的应用,info.plist 的以下版本是否相同?

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

这是cat /var/log/realm-object-server.log的结果:

2016-10-29T03:09:06.501Z - info: sync-server: Connection[5]: Connection from 127.0.0.1:58822
2016-10-29T03:09:06.631Z - info: sync-server: Connection[5]: Received: CLIENT(protocol_version=15, client_info_size=2, client_info='{}')
2016-10-29T03:09:06.788Z - info: sync-server: Connection[5]: Session[1]: Session initiated (session_ident=1).
2016-10-29T03:09:06.789Z - info: sync-server: Connection[5]: Session[1]: Received: BIND(server_path=/72c5a/realmtasks, signed_user_token='...xxm/7UjDkuEqQ==', need_file_ident_pair=0)
2016-10-29T03:09:06.789Z - info: sync-server: Connection[5]: Session[1]: Received: IDENT(server_file_ident=21314, client_file_ident=1, client_file_ident_secret=1477, scan_server_version=2, scan_client_version=2, latest_server_version=2, latest_server_session_ident=1643)
2016-10-29T03:09:17.069Z - info: sync-server: Connection[5]: Session[1]: Session terminated (session_ident=1).
2016-10-29T03:09:17.070Z - info: sync-server: Connection[5]: Connection closed by client: End of input
2016-10-29T03:09:26.769Z - info: sync-server: Connection[6]: Connection from 127.0.0.1:58866
2016-10-29T03:09:26.895Z - info: sync-server: Connection[6]: Received: CLIENT(protocol_version=15, client_info_size=2, client_info='{}')
2016-10-29T03:09:27.053Z - info: sync-server: Connection[6]: Session[1]: Session initiated (session_ident=1).
2016-10-29T03:09:27.053Z - info: sync-server: Connection[6]: Session[1]: Received: BIND(server_path=/a4fdec5a/realmtasks, signed_user_token='...K0k7mw==', need_file_ident_pair=0)
2016-10-29T03:09:27.053Z - info: sync-server: Connection[6]: Session[1]: Received: IDENT(server_file_ident=21094, client_file_ident=1, client_file_ident_secret=14907, scan_server_version=2, scan_client_version=2, latest_server_version=2, latest_server_session_ident=164553)

对象服务器正在运行,我可以看到 task 和 taskList 表,但我无法将记录写入表。

当我检查auth.log 时,我得到以下信息

Nov  1 10:53:22 digitalocean sshd[13684]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.229.172.111  user=root
Nov  1 10:53:49 digitalocean sshd[13701]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.229.172.111  user=root
Nov  1 10:53:50 digitalocean sshd[13701]: Failed password for root from 221.229.172.111 port 43992 ssh2
Nov  1 10:53:55 digitalocean sshd[13701]: message repeated 2 times: [ Failed password for root from 221.229.172.111 port 43992 ssh2]
Nov  1 10:53:55 digitalocean sshd[13701]: Received disconnect from 221.229.172.111 port 43992:11:  [preauth]
Nov  1 10:53:55 digitalocean sshd[13701]: Disconnected from 221.229.172.111 port 43992 [preauth]
Nov  1 10:53:55 digitalocean sshd[13701]: PAM 2 more authentication failures; logname= uid=0 euid=0 tty=ssh ruser= rhost=221.229.172.111  user=root

【问题讨论】:

  • 我将 ROS 部署到 Digital Ocean droplet (Ubuntu 16.04) 没有任何问题,并且我的部署运行良好。您是否考虑过破坏液滴并重新开始?也许部署中的某个步骤被遗漏或不按顺序完成 - 您可能会发现重新开始更容易。
  • 我的第一个 droplet 包括了防火墙并限制了对 ssh 的访问。我破坏了液滴并在没有这些的情况下重新开始,但仍然有问题。我不知道还要寻找什么。
  • 该死的。我真的创建了一个新的 droplet,创建了一个新的系统用户并赋予该用户 SUDO 权限,并按照 Realm Linux 安装说明进行操作。就是这样。它刚刚奏效。我想我会在以后处理防火墙和 ssl 等。祝你好运。
  • 谢谢伊恩。将尝试使用另一个新的液滴。
  • @IanBradbury 您是否在完成 Realm 移动平台任务示例/教程?您是否设法让它与 Ubuntu 服务器一起工作?

标签: realm realm-mobile-platform


【解决方案1】:

我想我找到了探针。

在教程的updateList()函数中:

func updateList() {
 if self.items.realm == nil, let list = self.realm.objects(TaskList.self).first {
  self.items = list.items
 }
 self.tableView.reloadData()
}

self.items 永远不会被设置,因为self.realm.objects(TaskList.self).first 将返回 nil,直到有任务添加到列表中。您需要添加一个任务(在我的例子中使用的是 Mac 版本的应用程序),然后 iOS 版本的代码才能工作。

【讨论】:

  • 是的,你是对的。您需要为 macOS 或 iOS 启动 RealmTasks,然后才能显示和创建其他任务。 > “如果您现在构建并运行应用程序,它应该连接到对象服务器并显示之前在 RealmTasks 中添加的任务。”
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-03-09
  • 1970-01-01
  • 2011-04-24
  • 1970-01-01
  • 2019-07-09
  • 1970-01-01
相关资源
最近更新 更多