CFNetwork Guide with Examples

Hi, I am new to Swift and looking to build some ping tool using raw socket. Can you point me to some training guides or books as I can understand how to use this library?

Just to set expectations here, CFNetwork is unlikely to be useful to you. CFNetwork is still relevant because it provides the underlying implementation for NSURLSession, but most of its other functionality has either been deprecated or has better alternatives.

As to how you should implement ping, I have two suggestions:

  • In general, follow the path laid down by the SimplePing sample code.

  • That code uses BSD Sockets for the core work and CFSocket for run loop integration. These days I recommend that you do the latter using a Dispatch source instead.


Oh, and please do file an enhancement request against Network framework for a explicit ping support. It’s annoying that you have to jump through all these hoops just to get that basic functionality.

I’d appreciate you posting your bug number here, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

CFNetwork Guide with Examples
 
 
Q