Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

beachdog

macrumors member
Original poster
Aug 10, 2008
86
0
I am building an application which will have a TCP socket connection to a server, over which a large number of messages will be exchanged. Many of the messages will be pushed from the server, and will need to update the UI. I am wondering if in a very network-intensive application such as this, whether I should use NSThread to create a separate runloop in which to do my network message processing, in order to keep it separate from the main thread that is handling the UI updates and other things. I guess I'm wondering if the UI is going to get sluggish when I amd processing large incoming messages. I tried searching the docs for some guidance/best practices on when to create different threads but didn't find any. Any advice from those who might have done something similar would be appreciated. Thx in advance
 
Yes; run your connections in a separate thread, or connect asynchronously. Otherwise you'll find your UI locking up whilst the connection blocks.

To update the UI from another thread you'll need to call a method on the main thread from your connection, something like:

Code:
[self performSelectorOnMainThread:@selector(yourMethodThatUpdatesTheUI:)
withObject:yourObjectFromYourConnection waitUntilDone:NO];
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.