当前位置:   article > 正文

CocoaAsyncSocket--mac Or iOS下封装好的Socket编程库(一)

CocoaAsyncSocket--mac Or iOS下封装好的Socket编程库(一)

首先,贴出其github地址:https://github.com/robbiehanson/CocoaAsyncSocket

接着,先来一段作者在github上提供的readme:(当然,我就大概地翻译一下吧,对己对人也有用)

CocoaAsyncSocket provides easy-to-use and powerful asynchronous socket libraries for Mac and iOS. The classes are described below.

CocoaAsyncSocket为mac和iOS开发提供了简单宜用且功能强大的异步socket库。

TCP

GCDAsyncSocket and AsyncSocket are TCP/IP socket networking libraries. Here are the key features available in both:

  • Native objective-c, fully self-contained in one class.纯OC原生语言,且高度集成,一个类包括一切
    No need to muck around with sockets or streams. This class handles everything for you.不需要分什么sockets或者streams了,这个类包含了一切。

  • Full delegate support全面的代理方法实现
    Errors, connections, read completions, write completions, progress, and disconnections all result in a call to your delegate method.错误、连接、读数据完成、写数据完成、进度、断开连接等等这一切的事件发生时,都会通过代理告诉你。

  • Queued non-blocking reads and writes, with optional timeouts.队列化的,非阻塞的读写操作,以及可选的超时机制。
    You tell it what to read or write, and it handles everything for you. Queueing, buffering, and searching for termination sequences within the stream - all handled for you automatically.一切都由你来决定,你来告诉它到底读什么写什么。至于队列、缓冲、寻找终止序列等等,都会自动帮你处理。

  • Automatic socket acceptance.自动化的套接字接收
    Spin up a server socket, tell it to accept connections, and it will call you with new instances of itself for each connection.启动一个服务端socket,告诉他等待连接申请,而当服务端接收到一个连接时,它会告诉你并返回一个新的实例。

  • Support for TCP streams over IPv4 and IPv6.支持IPv4或者IPv6协议下的tcp流
    Automatically connect to IPv4 or IPv6 hosts. Automatically accept incoming connections over both IPv4 and IPv6 with a single instance of this class. No more worrying about multiple sockets.

  • Support for TLS / SSL
    Secure your socket with ease using just a single method call. Available for both client and server sockets.

GCDAsyncSocket is built atop Grand Central Dispatch:

  • Fully GCD based and Thread-Safe基于GCD(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.

  • The Latest Technology & Performance Optimizations
    Internally the library takes advantage of technologies such as kqueue's to limit system calls and optimize buffer allocations. In other words, peak performance.

AsyncSocket wraps CFSocket and CFStream:

  • Fully Run-loop based
    Use it on the main thread or a worker thread. It plugs into the NSRunLoop with configurable modes.

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 is built atop Grand Central Dispatch:

  • Fully GCD based and Thread-Safe
    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 wraps CFSocket:

    • Fully Run-loop based
      Use it on the main thread or a worker thread. It plugs into the NSRunLoop with configurable modes.

 

下一篇再继续讨论下实战使用吧。

转载于:https://www.cnblogs.com/nathanou/p/3253167.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/代码探险家/article/detail/808242
推荐阅读
相关标签
  

闽ICP备14008679号