I haven't been able to find a solid answer to this question anywhere on the internet, and I feel like there has to be a simple answer. I'm trying to test wether I have a connection to specific ip addresses and certain ports with Swift on Mac OS.
I really just want to return true/false if I'm able to connect to a URL, or specific ports associated with it.
Any ideas?
Have a look at the
Networkframework. It is super powerful and flexible and allows direct access to protocols like TLS, TCP, and UDP for your custom application protocols. It is Swift-ready and easy to use.The code above will work even in Playground (and fire the
stateUpdateHandlerat least once). In real appstateUpdateHandlerwill be called every time the state changes. BTW,URLSession, is built upon this framework.