Re: GUI not responding possibly because of NSRunLoop, what can I do?
Re: GUI not responding possibly because of NSRunLoop, what can I do?
- Subject: Re: GUI not responding possibly because of NSRunLoop, what can I do?
- From: Alastair Houghton <email@hidden>
- Date: Tue, 7 Aug 2007 10:04:18 +0100
On 7 Aug 2007, at 02:00, Devraj Mukherjee wrote:
I am trying to use NetSocket to read data from a TCP socket and parse
a text based protocol. The parsed messages then raise notifications
and I wish to show some GUI elements for the user to interact with.
An example that was distributed with the NetSocket class suggested
that I run [[NSRunLoop currentLoop] run] to keep listening to the
socket for data.
Sounds wrong to me. Your application will already be running the run
loop when you return from an event handler. You need to write your
code in an asynchronous style---i.e. have NetSocket notify you when
data is available, read that data, then return. You can do that by
setting the delegate of your NetSocket object, then implementing the -
socket:dataAvailable: method. Otherwise, you'll need to use a
separate thread, in which case using something like NetSocket or
AsyncSocket is pointless.
Running embedded event loops is very rarely the right way to go, and
even then, calling -run is almost never the right thing to do because
-run never returns (which is the root of your problem here I
suspect). The only time you *might* call -run is in a command line
application, but from what you've said, your app is not one of those.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
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