Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save adrianjagielak/342745ccb401d80a40ea9e1593debbd3 to your computer and use it in GitHub Desktop.
Save adrianjagielak/342745ccb401d80a40ea9e1593debbd3 to your computer and use it in GitHub Desktop.
Obtaining NWEndpoint host & port
let connection = NWConnection(to: result.endpoint, using: .tcp)
connection.stateUpdateHandler = { state in
switch state {
case .ready:
if let innerEndpoint = connection.currentPath?.remoteEndpoint,
case .hostPort(let host, let port) = innerEndpoint
{
print("Connected to", "\(host):\(port)")
} else {
print("Failed finding ip:host")
}
connection.stateUpdateHandler = nil
connection.cancel()
default:
break
}
}
connection.start(queue: .global())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment