swiftsocket / SwiftSocket

The easy way to use sockets on Apple platforms
BSD 3-Clause "New" or "Revised" License
1.69k stars 400 forks source link

Swift Socket not resolving dns in ios 11 #118

Open sumeet-gluon opened 7 years ago

sumeet-gluon commented 7 years ago
  This code works till iOS 10. however it stopped working when I upgraded to iOS 11. I debugged and found the problem in ytcpsocket_connect.c gethostbyname() function is unable to resolve the DNS and the library always returns the queryFailed error. Please advise.

   var client = TCPClient(address: "device.abc.com", port: Int32(5001))
   switch client.connect(timeout: 5) {
                case .success:
                   print("connected")
                case .failure(let error):
                    print("Socker Error Reason - \(error)")
  }
abbasqamar commented 6 years ago

Same issue .. my app rejected bcz unable to resolve the ipv6 address

HeartOfGold523 commented 6 years ago

Are there any updates to this issue? I have the exact same problem that no matter what address I put into the TCPClient, connecting always returns the queryFailed error.

I confirmed that mine was also acting up in the file "ytcpsocket.c" (Pods/SwiftSocket/ytcpsocket.c) in the function "ytcpsocket_connect". The issue is that after the call hp = gethostbyname(host) is executed, hp is always null, and thus returns -1.

Please, if someone has figured out how to move passed this, any help would be much appreciated!

sumeet-gluon commented 6 years ago

I had to use the IP itself to connect. DNS name didn't work.

shirishbankar1 commented 4 years ago

@abbasqamar did you get any solution to connect via ipv6 address ? It gives me query failed error.

BrandonMFong commented 2 months ago

I just needed to go into Target Settings -> Signing & Capabilities and enable:

Incoming network connections (server).
Outgoing network connections (client)