Re: Socket Blocking Question
Re: Socket Blocking Question
- Subject: Re: Socket Blocking Question
- From: Ken Thomases <email@hidden>
- Date: Wed, 20 Jan 2010 13:23:39 -0600
On Jan 20, 2010, at 11:39 AM, Carter R. Harrison wrote:
> I need some folks experienced with cocoa and socket programming to weigh in for me on some design problems I've been having. I'm designing an application that acts as a client in a client-server model. The client communicates with the server over the network by issuing a request and then receiving a response. Requests can only be issued one at a time, meaning that a request cannot be sent until a response from any outstanding request is first received. My application works in such a way that the it could request a handle to an object on the server and then use that handle in subsequent requests to retrieve additional information about the object. I see two ways of modeling the application - I've tried both and I'm not particularly happy with either.
>
> The first is to send a request, and then have the socket block until a response is received. This benefit to this model is that it is so much easier to write the higher level application code. The issue with this model is that over a slow network connection it can take a considerable amount of time for the response to come back from the server and while that is happening my CPU usage is through the roof b/c the thread is blocking.
If you're using lots of CPU time, then you're not blocking, you're spinning. When a thread is blocked, it does nothing and consumes no CPU time.
Now, blocking is bad in the main thread of a GUI app, but if you're writing non-GUI code, it can be a perfectly sensible design approach. However, you have to actually implement blocking!
Cheers,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden