我想使用Realm Object Server在智能手机之间共享数据,我用Swift制作了这段代码。 (我使用Realm - > 3.0.2 ROS - >最新)
let realmAuthURL = URL(string:"http://[server_address]:9080")!
let realmURL = URL(string:"realm://[server_address]:9080/~/realm")!
let credentials = SyncCredentials.usernamePassword(username: "[username]", password: "[password]")
SyncUser.logIn(with: credentials, server: realmAuthURL) { user, error in
DispatchQueue.main.async {
if let user = user {
Realm.Configuration.defaultConfiguration = Realm.Configuration(
syncConfiguration: SyncConfiguration(user: user, realmURL: realmURL),
objectTypes: [PCData.self]
)
print("ログインに成功しました")
self.realm = try! Realm(configuration: Realm.Configuration.defaultConfiguration)
//print(self.realm.objects(PCData.self))
if self.realm.isEmpty {
try! self.realm.write {
let data = PCData()
data.isOut = false
data.pcCode = "***METADATA***"
data.rentPCto = ""
data.IDinCourse = 999999999999
data.belonging = "Master"
self.realm.add(data)
}
}
}
}
}
当我尝试时,输出“ログインに成功しました”,服务器有似乎已被访问过的日志
然而,
2017-12-17 22:53:30.880875+0900 PCManage[7021:1784833] Sync: Connection[1]: Connection closed due to error
2017-12-17 22:53:31.673562+0900 PCManage[7021:1784833] Sync: Connection[1]: Connected to endpoint '[Server's IP]:9080' (from '[My IP]:57032')
2017-12-17 22:53:31.684189+0900 PCManage[7021:1784833] Sync: Connection[1]: Writing failed: End of input
无法获取数据等 在服务器中。
proxy: attempting to upgrade client [My IP]:57032 => headers: {"authorization":"Realm-Access-Token version=1 token=\"eyJhY2Nlc3MiOlsiZG93bmxvYWQiLCJ1cGxvYWQiLCJtYW5hZ2UiXSwiYXBwX2lkIjoiY29tLmFrYmFydC5hcHAuUVJ0ZXN0IiwiZXhwaXJlcyI6MTUxMzUxOTQwOCwiaWQiOiIwMzdmY2I5Yzc0MGE0ZjdhOGVhOTZkZmFhYjUxNmM2ZiIsImlkZW50aXR5IjoiZmI0NmQ1ZjNjYjRiNmE5NWExYWYyNDkzZGIxNjE5YzYiLCJwYXRoIjoiL2ZiNDZkNWYzY2I0YjZhOTVhMWFmMjQ5M2RiMTYxOWM2L3JlYWxtIn0=:Tn4Qa4vzvZ87lnW2htmt6rPCaLL5ASDkpqbcXT2eKskQ3NHJ3ePyMxvJjjyAq5rh8pb2syCM1Dh8LrVk9RilQsHwHRU9HyDOky/psePE4UfXidEJGYoML19R9mo+yjHPG7DeP0ykYltTjONJh+OpQkaelHYIMlKAwFP+hxeNWlVAIpjohkqmyr/de3++8IxcVV6/6wJUESdNpDq2e5GGKfxpSwbfhBagNi0m0aSNuwzoqJ5CFqbyoxsyyCZWx6XJ7ZueTmRvGx22SJcthRzxrQRrWMbMtF8yEHY/AARzycO/A/Zi5spXqAzQD6QIrkl5gGI/FwvnLvhvtPEFychXIg==\"","connection":"Upgrade","host":"[]","sec-websocket-key":"K0Tw7zhY3ov9h+VEqHtaPQ==","sec-websocket-protocol":"io.realm.sync.22","sec-websocket-version":"13","upgrade":"websocket"}.}
sync: HTTP Connection[959]: Connection from 127.0.0.1:35414
sync: HTTP Connection[959]: Connection initiates HTTP receipt
sync: HTTP Connection[959]: HTTP request received, url = /realm-sync/%2Ffb46d5f3cb4b6a95a1af2493db1619c6%2Frealm
sync: HTTP Connection[959]: 404 Not Found
sync: HTTP Connection[959]: Connection is closed after HTTP response.
显示404 Not Fount 我认为服务器端现在很奇怪,但我没有从初始设置改变,所以我不知道哪里出错了 我怎样才能获得数据?
答案 0 :(得分:0)
您共享的日志消息似乎表明您正在使用Realm Object Server v1.x. Realm Swift 3.x需要Realm Object Server v2.x.有关安装ROS v2.x的说明,请参阅Realm Object Server documentation。