• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: GUI not responding possibly because of NSRunLoop, what can I do?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >GUI not responding possibly because of NSRunLoop, what can I do? (From: "Devraj Mukherjee" <email@hidden>)
 >Re: GUI not responding possibly because of NSRunLoop, what can I do? (From: Alastair Houghton <email@hidden>)

  • Prev by Date: image buttons + weird "focus" highlights
  • Next by Date: drawing a simple string with NSFont
  • Previous by thread: Re: GUI not responding possibly because of NSRunLoop, what can I do?
  • Next by thread: Re: GUI not responding possibly because of NSRunLoop, what can I do?
  • Index(es):
    • Date
    • Thread