CocoaAsyncSocket第三方库的存储地址是:https://github.com/robbiehanson/CocoaAsyncSocket
CocoaAsyncSocket为Mac和iOS提高易于使用的、强大的异步套接字库。类的描述如下:
TCP
GCDAsyncSocket and AsyncSocket are TCP/IP socket networking libraries. Here are the key features available in both:
GCDAsyncSocket和AsyncSocket 是TCP/IP套接字网络连接库。俩个库的关键特点如下:
-
Native objective-c, fully self-contained in one class.
不需要搞乱套接字或者数据流。这个类为你操控一切。 -
Full delegate support
错误、连接、完成读、完成写、进程和断开这些所有的结构都能在你的代理方法调用中使用。
-
Queued non-blocking reads and writes, with optional timeouts.
你告诉类要读写什么,这个类就为你操作一切。排队、缓冲和寻找数据流内的终止序列-------以上所有的操作都是自动的。 -
Automatic socket acceptance.
打开一个服务套接字,告诉它接收连接,他将用它的新实例来调用你来达到每一个连接。
-
Support for TCP streams over IPv4 and IPv6.
自动连接到IPV4和IPV6的主机上。自动接收同时在IPV4和IPV6带有单个实例的类传入的连接。不用担心多个套接字。
-
Support for TLS / SSL支持TLS/SSL
确保你的套接字能够轻易的使用一个单个的方法调用。并且可以在服务器和客户端可以使用套接字。
GCDAsyncSocket被建立在中亚调度上:
-
完全基于GCD和线程安全:
它完全运行在它自己的GCD调度队列内,并且是完全是线程安全的。另外,代理方法都被异步调用到你选择的调度队列上。这个方法使你的套接字代码操作和你的代理/进程代码平行。
-
最新的技术和性能优化。
在内部这个库充分利用例如kqueue的技术来限制系统调用和优化缓冲分配。话句话来说就是峰值性能。
AsyncSocket包装CFSocket和CFStream:
- 完全基于Run-loop
在主线程和工作线程上使用AsyncSocket。它插入到有可配置模式的NSRunLoop里。
UDP
GCDAsyncUdpSocket and AsyncUdpSocket are UDP/IP socket networking libraries. Here are the key features available in both:
-
Native objective-c, fully self-contained in one class.
No need to muck around with low-level sockets. This class handles everything for you. -
Full delegate support.
Errors, send completions, receive completions, and disconnections all result in a call to your delegate method. -
Queued non-blocking send and receive operations, with optional timeouts.
You tell it what to send or receive, and it handles everything for you. Queueing, buffering, waiting and checking errno - all handled for you automatically. -
Support for IPv4 and IPv6.
Automatically send/recv using IPv4 and/or IPv6. No more worrying about multiple sockets.
GCDAsyncUdpSocket 是被建立在Grand Central Dispatch上的:
- 完全基于GCD并且是线程安全的。
It runs entirely within its own GCD dispatch_queue, and is completely thread-safe. Further, the delegate methods are all invoked asynchronously onto a dispatch_queue of your choosing. This means parallel operation of your socket code, and your delegate/processing code.
AsyncUdpSocket包装CFSocket:
- 完全基于Run-loop
在主线程和工作者线程上使用AsyncUdpSocket。AsyncUdpSocket插到具有可配置的NSRunLoop中。