3

One is GCD and other is Runloop?It is abstract,how to choose one for my TCP connect ?Very thankful,i only find how to use GCDAsyncSocket on github,but dont know how to choose one.

Moin Shirazi
  • 4,372
  • 2
  • 26
  • 38
Kira
  • 243
  • 2
  • 9

1 Answers1

8

Hope this may help you:

Even if you're on iOS only, there will likely be multi-core iOS devices in the near future. And GCD will be an excellent way to take advantage of the additional resources with GCDAsyncSocket

GCDAsyncSocket

  • The minimum requirements for GCDAsyncSocket:Mac OS X 10.6+ or iOS 4.0+

  • GCDAsyncSocket performs much better than AsyncSocket.

  • Considering off-loading the encryption/descryption (not SSL/TLS) onto another thread and it seems to me that going the way of GCD would be the better alternative.

Specific features of GCDAsyncSocket include:

    1. Classic delegate-style support.
    2. It allows allows for parallel socket IO and data processing, as well as easy thread-safety.
    3. Queued non-blocking reads and writes, with optional timeouts.
    4. Automatic support for IPv4 and IPv6.
    5. SSL/TLS support.
    6. Built upon the latest technologies such as queues and GCD.
    7. Self-contained in one class.
    You don't need to muck around with streams or sockets. The class handles all of that.

AsyncSocket

The AsyncSocket library is composed of one class, also called AsyncSocket. An instance of AsyncSocket represents one socket, which may be a listen socket or a connect socket.

  • If you need to support OS versions prior to Mac OS X 10.6+ or iOS 4.0+, then you'll need to stick with AsyncSocket for now.

  • AsyncSocket provides easy-to-integrate “fire and forget” networking that makes it easy for your application to support networking.

Features include:

•   Queued non-blocking reads and writes, with timeouts.
•   Automatic socket acceptance.
•   Delegate support.
•   Run-loop based, not thread based.
•   Self-contained in one class. You do not need to muck around with a collection of stream or socket instances. The class handles all of that.
•   Support for TCP streams. AsyncSocket does not support UDP or multicast sockets.
•   Based on Apple’s own CFSocket and CFStream Carbon APIs.

Reference Reference_GCDAsyncSocket

Reference About AsyncSocket

soumya
  • 3,801
  • 9
  • 35
  • 69