Question

I am needing to write a CalDAV client library for the Mac, and I just wanted to make sure on what would be the best way to write it.

I am wondering if I should just use NSURLRequest or should I go to the socket level, or something in between?

My concern about using just NSURLRequest is that a new connection would be made for each call, instead of having 1 open connection that all "requests" go through.

Am I missing something?

Thoughts? Suggestions?

Was it helpful?

Solution

NSURLRequest doesn't actually create any connections. It just encapsulates the parameters of the request. NSURLConnection actually creates the connection to the server and sends the request. Under the covers, NSURLConnection instances share and reuse TCP connections, according to this answer:

NSURLConnection is run many times

So you should just use NSURLRequest and NSURLConnection if their APIs suit you.

OTHER TIPS

Use NSURLRequest. Despite the naming, an NSURLConnection object does not have a one-to-one correspondence with a TCP connection. In fact, NSURLConnection might be more appropriately named NSURLRequestLoadingManager or something—it's just an object that tracks the progress of that particular request.

The underlying TCP connections are managed by Cocoa, and you don't need to worry about their lifecycle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top