• 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: multithreaded vs ...?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: multithreaded vs ...?


  • Subject: Re: multithreaded vs ...?
  • From: email@hidden
  • Date: Mon, 18 Feb 2002 09:01:58 -0800

On Sunday, February 17, 2002, at 11:32 PM, Jason Kuri wrote:

I'm developing a cocoa framework to interface with a server using a network messaging protocol (tcp based, variable-length records). The concept is to provide a connection object which an app can use to handle all communications with the server. (Basically dealing with the connection process and complexities of packet arrival and decoding, encoding, etc.)

My question is, given that the object will have to deal with packets arriving at random times and that they will need to be dealt with relatively quickly, what is the best way to incorporate my network-processing into the applications event-loop?

If I were writing this in C, I would either create a separate thread for handling network activity, or use nonblocking io and a select() loop with callback functions. I think I have a reasonable understanding of NSApplication and multi-threading in cocoa. Based on what I've read, I have come to the conclusion that the best way to handle this is to require that my connection-object operate in it's own thread... but as I am relatively new to cocoa programming, I'd like to get a second opinion. Is there a better way to handle this? I'm concerned that forcing it into it's own thread will make using the framework overly complicated.

Does anyone have any advice or pointers they could share? I'm guessing my question has a fairly straightforward answer, but I'm relatively new to Cocoa programming (though I've been programming Unix-C for years), and I would really appreciate any pointers anyone can provide.

Assuming that your network packets are going to cause user interface changes, I would suggest that you do your IO in the main runloop. do your accepts, reads and writes in non-blocking io via readInBackgroundAndNotify and similar constructs.

Using threads in Cocoa is an over-complex obfuscated mess. It is the one place that Java actually is better than Objective-C.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
  • Follow-Ups:
    • Re: multithreaded vs ...?
      • From: Jay Kuri <email@hidden>
    • Re: multithreaded vs ...?
      • From: Raphael Sebbe <email@hidden>
References: 
 >multithreaded vs ...? (From: Jason Kuri <email@hidden>)

  • Prev by Date: Re: Tiff with mask
  • Next by Date: 2 Newbie questions
  • Previous by thread: multithreaded vs ...?
  • Next by thread: Re: multithreaded vs ...?
  • Index(es):
    • Date
    • Thread