On 20 Jan 09, at 13:36, Mohan Parthasarathy wrote:
On Tue, Jan 20, 2009 at 1:23 PM, Andrew Farmer <andf...@gmail.com> wrote:
On 20 Jan 09, at 12:22, Mohan Parthasarathy wrote:

I want to be able to establish the TCP connection to a server and do
multiple HTTP GETs with different URLs. I thought will achieve this by allocating a NSURLConnection and then initWithRequest:urlRequest with a different URL everytime as there is no other way to set the URL. It looks
like that this is not working and the URL is not changing.

Initializing ObjC objects multiple times is always incorrect. Don't do it!

Ok. Is it because init assumes that it is allocating memory for the first time and hence may cause leaks if called multiple times ? At least it seems
to work now.

Internally, any number of things may be happening during initialization. Calling the initializer multiple times on an object is invalid, and may result in memory leaks, crashes, or other incorrect behavior; moreover, even if it appears to work correctly in a given system version, there is no guarantee that it will continue to behave similarly in future versions of the OS. Even minor updates may change the behavior - it's undefined, and is under absolutely no obligation to remain constant.

Seriously, don't do it.

Is there a way to not to allocate the connection everytime i need to send
a new request ?

Yes. I'm pretty sure that the URL loading framework will use HTTP
keepalives automatically when appropriate.

I am not sure i undrstood this. If i allocate a NSURL connection everytime i need to fetch from a URL, wouldn't it set up a TCP connection everytime
and then download the data. If i can avoid that, wouldn't it be nice ?

Again, I'm pretty sure that the Cocoa URL loading functions will do this for you as appropriate. Trying to implement it yourself is unnecessary, and trying to go about it this particular way is futile as well as incorrect.
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to