Reputation: 1662
I have an issue when connect to Realm Object Server on my device but it works on simulator. it's return errors :
Error Domain=NSURLErrorDomain Code=-1004 "Could not connect to the server."
UserInfo={NSUnderlyingError=0x170255450 {Error
Domain=kCFErrorDomainCFNetwork Code=-1004 "(null)" UserInfo=
{_kCFStreamErrorCodeKey=61, _kCFStreamErrorDomainKey=1}},
NSErrorFailingURLStringKey=http://127.0.0.1:9080/auth,
NSErrorFailingURLKey=http://127.0.0.1:9080/auth, _kCFStreamErrorDomainKey=1,
_kCFStreamErrorCodeKey=61, NSLocalizedDescription=Could not connect to the
server.}): file
/Users/tungvu/Desktop/Swift3Xcode8/RealmTask/RealmTask/ViewController.swift,
line 57
Here's my connect to Realm Object Server function:
SyncUser.logIn(with: .usernamePassword(username: username, password: password, register: false), server: URL(string : "http://127.0.0.1:9080")!) { (user, error) in
guard let user = user else {
fatalError(String(describing: error))
}
DispatchQueue.main.async {
// Open Realm
let configuration = Realm.Configuration(
syncConfiguration: SyncConfiguration(user: user, realmURL: URL(string: "realm://127.0.0.1:9080/~/realmtasks")!)
)
Upvotes: 0
Views: 568
Reputation: 15991
From the looks of it, you're using the localhost IP address 127.0.0.1
. While this will work with apps running on the same device as the Realm Object Server instance (ie the iOS Simulator), you'll need the actual IP address of the machine on the local network in order to connect from a separate device like an iPhone.
The easiest way to find the network IP address is to hold down Alt, and then click on the Wi-Fi icon in the macOS status bar:
If you replace 127.0.0.1
with your Mac's network IP address, other devices should then be able to connect to it. This should work for the iOS Simulator as well, so there shouldn't be a need to change it until your machine's IP address changes.
Upvotes: 2