CocoaAsyncSocket 套接字

简介:

CocoaAsyncSocket   套接字

https://github.com/robbiehanson/CocoaAsyncSocket

 

Asynchronous socket networking library for Mac and iOS

用于iOS以及Mac的异步套接字网络库。

 

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.
    No need to muck around with sockets or streams. This class handles everything for you.

  • 原生的OC,完整的一个类,不需要你去染指sockets或者是流,这个类帮你搞定了所有的封装。
  • Full delegate support
    Errors, connections, read completions, write completions, progress, and disconnections all result in a call to your delegate method.

  • 完整的代理来支持Errors,链接,读操作,写操作,进度以及断开链接,所有的这些都在代理方法中调用。
  • 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.

  • 自动套接字接收。连接上服务器,告知它接受链接,之后,它会自己创建一个实例对象来维持这次链接。
  • Support for TCP streams over IPv4 and IPv6.
    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.

  • 支持IPv4以及IPv6的TCP流。自动连接IPv4或者IPv6的主机。自动接收来自IPv4或者IPv6的连接,只用一个实例对象,你不用担心重复的套接字。
  • Support for TLS / SSL
    Secure your socket with ease using just a single method call. Available for both client and server sockets.

  • 支持TLS/SSL,加密你的socket,只需调用一个方法,支持服务器或者客户机套接字。

GCDAsyncSocket is built atop Grand Central Dispatch:

GCDAsyncSocket基于GCD扩展出的:

  • Fully GCD based and Thread-Safe
    It runs entirely within its own GCD dispatchqueue, 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.

  • 基于GCD以及完全的线程安全,它内置了GCD线程池。
  • 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:

AsyncSocket封装了CFSocket和CFStream:

  • Fully Run-loop based
    Use it on the main thread or a worker thread. It plugs into the NSRunLoop with configurable modes.
  • 基于Run-loop,在主线程或者一个其他线程中使用,它会用一些配置来插入到NSRunLoop中。

 

 

UDP

GCDAsyncUdpSocket and AsyncUdpSocket are UDP/IP socket networking libraries. Here are the key features available in both:

GCDAsyncUdpSocket和AsyncUdpSocket是UDP/IP套接字网络库。以下是它们的特性:

  • Native objective-c, fully self-contained in one class.
    No need to muck around with low-level sockets. This class handles everything for you.

  • 原生的OC,完整的一个类,不需要你去染指sockets或者是流,这个类帮你搞定了所有的封装。
  • Full delegate support.
    Errors, send completions, receive completions, and disconnections all result in a call to your delegate method.

  • 完整的代理来支持Errors,链接,读操作,写操作,进度以及断开链接,所有的这些都在代理方法中调用。
  • 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.

  • 支持IPv4以及IPv6的TCP流。自动连接IPv4或者IPv6的主机。自动接收来自IPv4或者IPv6的连接,只用一个实例对象,你不用担心重复的套接字。

GCDAsyncUdpSocket is built atop Grand Central Dispatch:

GCDAsyncUdpSocket基于GCD扩展出的:

  • Fully GCD based and Thread-Safe
    It runs entirely within its own GCD dispatchqueue, 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.
  • 基于GCD以及完全的线程安全,它内置了GCD线程池。

AsyncUdpSocket wraps CFSocket:

AsyncUdpSocket封装了CFSocket:

    • Fully Run-loop based
      Use it on the main thread or a worker thread. It plugs into the NSRunLoop with configurable modes.
    • 基于Run-loop,在主线程或者一个其他线程中使用,它会用一些配置来插入到NSRunLoop中。

 

目录
相关文章
|
2月前
|
网络协议 Java Unix
套接字(Socket)
套接字(Socket)
22 3
|
1月前
|
网络协议 数据库连接
套接字双向通信
套接字双向通信
21 5
|
1月前
套接字(socket)的端点表示
套接字(socket)的端点表示
22 8
|
6月前
|
存储
14.10 Socket 套接字选择通信
对于网络通信中的服务端来说,显然不可能是一对一的,我们所希望的是服务端启用一份则可以选择性的与特定一个客户端通信,而当不需要与客户端通信时,则只需要将该套接字挂到链表中存储并等待后续操作,套接字服务端通过多线程实现存储套接字和选择通信,可以提高服务端的并发性能,使其能够同时处理多个客户端的请求。在实际应用场景中,这种技术被广泛应用于网络编程、互联网应用等领域。在服务端启动时,创建套接字并进行绑定,然后开启一个线程(称为主线程)用于监听客户端的连接请求。主线程在接收到新的连接请求后,会将对应的套接字加入一个数据结构(例如链表、队列、哈希表等)中进行存储。同时,主线程会将存储套接字的数据结构传递给
25 1
14.10 Socket 套接字选择通信
|
2月前
|
缓存 网络协议 API
套接字
Socket的连接 更准确来说是,流式Socket连接的相关内容 基本概述: TCP通信需要先建立虚拟链路(通信双方的一个连接,connection),TCP/IP通讯下,Socket采用四元组(源IP、源端口、目的IP、目的端口)标识(identity)
|
1月前
|
网络协议 Python
创建套接字
创建套接字
19 6
|
3月前
|
网络协议 Java 程序员
网络编程套接字(Socket)
网络编程套接字(Socket)
37 0
|
8月前
|
网络协议 Java API
|
7月前
|
网络协议 开发者 Python
套接字的使用
套接字的使用
67 0
|
11月前
|
缓存 网络协议 Java
网络编程套接字Socket
网络编程套接字Socket