CocoaAsyncSocket 套接字

2024-09-05 13:32
文章标签 接字 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中。

这篇关于CocoaAsyncSocket 套接字的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1139091

相关文章

微软C#套接字异步通信代码

Asynchronous Server Socket Example.NET Framework 4 其他版本 The following example program creates a server that receives connection requests from clients. The server is built with an asynchronous socket,

套接字的介绍

套接字(Socket)是计算机网络中用于实现不同主机之间通信的一种抽象概念。它提供了一种标准的接口,使得应用程序能够通过网络发送和接收数据。以下是关于套接字的详细介绍: 1. 套接字的基本概念 定义:套接字是一种用于网络通信的端点,通常由 IP 地址和端口号组成。它允许不同的程序进行网络通信。类型: 流套接字(TCP Socket):使用传输控制协议(TCP),提供可靠的、面向连接的通信。数据

JAVAEE初阶第六节——网络编程套接字

系列文章目录 JAVAEE初阶第六节——网络编程套接字 文章目录 系列文章目录JAVAEE初阶第六节——网络编程套接字 一. 网络编程基础1. 为什么需要网络编程2. 什么是网络编程3.网络编程中的基本概念 3.1 发送端和接收端 3.2 请求和响应 3.3 客户端和服务端 4. 常见的客户端服务端模型 5. TCP和UDP特点上的差别(初识) 二.Socket套接字 1. 概

网络编程套接字(Socket)详解 V✪ω✪V

目录 🍈一.什么是网络编程 1.1什么是网络编程? 1.2网络通信中的基本概念: 🍇二.Soket(套接字)→网络编程的基础 2.1概念: 2.2Socket套接字分类: 数据包套接字:使用传输层UDP协议 流套接字:使用传输层TCP协议 🍊三.UDP通信程序 3.1UDP通信的流程: 3.2通过UDP实现服务器客户端的交互: 🥥四.TCP通信程序 ​编辑

网络编程套接字(含Java示例)

文章目录 Socket套接字概念分类流式套接字:使用传输层TCP协议数据报套接字:使用传输层UDP协议Unix域套接字 TCP vs UDP有连接 vs 无连接可靠传输 vs 不可靠传输面向字节流 vs 面向数据报全双工 vs 半双工 UDP数据报套接字编程DatagramSocketDatagramPacket代码示例 TCP流套接字编程ServerSocket(专门给服务器用的)Soc

JavaEE第19节 用UDP套接字实现简单回显服务器

目录 一、API介绍`DatagramSocket` 用于发送和接收数据报。`DatagramPacket` 是UDP对数据的封装的基本单位 二、创建简单的回显服务器 服务器端 客户端 三、程序优化 一、API介绍 UDP协议面向数据报进行传输,所以在代码中基本是以数据报(DatagramPacket)作为操作对象,进行输入和输出的。 JAVA提供了两个常用的类去操作UDP套接字

【案例64】无法从套接字读取更多的数据

问题现象 系统突然间登录报如下错误:SELECT * FROM sm_user WHERE user_code_q=? 无法从套接字读取更多的数据 问题分析  查看nc-log.log发现大量相关报错 $$callid=1723104097968-1063 $$thread=[http-bio-xxx-xxx-exec-xxx] $$host=xxx$$userid=#UAP#

Error querying database. Cause: java.sql.SQLException: 无法从套接字读取更多的数据

java + oracle 查询报错: Cause: java.sql.SQLException: 无法从套接字读取更多的数据;uncategorized SQLException for SQL []; SQL state [null]; error code [17410]; 无法从套接字读取更多的数据; nested exception is java.sql.SQLException:

linux文件描述符和套接字的问题

记得刚学linux的时候 就会听到一句"一切皆文件" 上面标准输入 标准输出 标准错误 重定向 blablabla... 今天在写一个基于epoll的聊天室  客户端fork 父进程负责读 子进程负责写 感觉这好像服务端 主从备份..还像nginx中的进程的模型,各个worker 从 listen 后的 master fork出来的 master负责分发 worker负责处理  主要是映射到各个

重头开始嵌入式第二十八天(Linux系统编程 网络通信 套接字)

目录 1.网络编程  1.OSI(Open System Interconnection)模型即开放式系统互联通信参考模型。 TFTP(Trivial File Transfer Protocol)即简单文件传输协议。 2.  TCP/IP模型也叫网际互联模型共分为4层:也叫协议栈 3、TCP/IP协议族: 4.DNS(Domain Name System,域名系统)是互联网的一项