From ccbc609bdffb8eb75231bfc586383885172c8118 Mon Sep 17 00:00:00 2001 From: tangjiapeng Date: Thu, 5 Jun 2025 12:09:48 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0ReadME=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.en.md | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 30 ++++++++++++++----- 2 files changed, 105 insertions(+), 7 deletions(-) create mode 100644 README.en.md diff --git a/README.en.md b/README.en.md new file mode 100644 index 0000000..0ba8bf6 --- /dev/null +++ b/README.en.md @@ -0,0 +1,82 @@ +# ios-async-socket-explorer (EN) + +A production-ready TCP communication framework for iOS, designed for high-concurrency, weak network environments, and modular architecture in enterprise-level applications. + +## ✨ Overview + +`ios-async-socket-explorer` is an industrial-grade TCP socket framework built on CocoaAsyncSocket, abstracted from real-world enterprise IM systems. + +- Supports **3000+ concurrent connections**, handling **100,000+ messages daily** +- Implements **TLV binary protocol**, **CRC32 checksum**, and **ACK-based reliability mechanism** +- Equipped with **RTT-adaptive heartbeat** and **exponential backoff reconnection**, optimized for complex weak network conditions +- Features **enterprise-level VIPER architecture**, with **unit test coverage over 85%** +- Provides **comprehensive monitoring metrics and full-link tracing** to ensure system observability + +## 🔧 Why not just use WebSocket? + +| Comparison | Advantage of CocoaAsyncSocket | +|------------|-------------------------------| +| Custom protocol support | Enables binary framing, versioning, compression | +| Fine-grained control | Better handling of sessions, retries, and heartbeats | +| Enterprise security | Supports TLS, keepalive, session isolation | +| Flexibility | Objective-C base, easy Swift integration | + +## 🚀 Quick Start +**Objective-C Example** + +```Objc +// 0. Add this in AppDelegate +[TJPMessageFactory load]; + +// 1. Initialize the client +TJPIMClient *client = [TJPIMClient shared]; +// It's recommended to keep 'client' as a member variable to avoid premature release + +// 2. Establish different session connections +[client connectToHost:@"media.example.com" port:8080 forType:TJPSessionTypeChat]; +[client connectToHost:@"media.example.com" port:8081 forType:TJPSessionTypeMedia]; + +// 3. Create different types of messages +TJPTextMessage *textMsg = [[TJPTextMessage alloc] initWithText:@"Hello World!!!!!"]; +// 4.1 Send message - specify session manually +[client sendMessage:textMsg throughType:TJPSessionTypeChat]; + +// 4.2 Send message - auto route +TJPMediaMessage *mediaMsg = [[TJPMediaMessage alloc] initWithMediaId:@"12345"]; +[client sendMessageWithAutoRoute:mediaMsg]; // Automatically routed to media session +``` + +**Swift Example** + +```Swift +// 0. Add this in AppDelegate +TJPMessageFactory.load() + +// 1. Initialize the client +let client = TJPIMClient.shared +// It's recommended to keep 'client' as a property to avoid premature deallocation + +// 2. Establish different session connections +client.connect(toHost: "media.example.com", port: 8080, for: .chat) +client.connect(toHost: "media.example.com", port: 8081, for: .media) + +// 3. Create different types of messages +let textMsg = TJPTextMessage(text: "Hello World!!!!!") +// 4.1 Send message - specify session manually +client.sendMessage(textMsg, through: .chat) + +// 4.2 Send message - auto route +let mediaMsg = TJPMediaMessage(mediaId: "12345") +client.sendMessageWithAutoRoute(mediaMsg) // Automatically routed to media session +``` + +## License & Disclaimer +This project is released under the **MIT License** and intended for personal study and research purposes only. Please be aware of the following before using: + +1. You are free to modify and distribute the code, but it's **not recommended** to use it directly in production applications. +2. Ensure your usage **complies with relevant data privacy regulations**. +3. Given the complexity and variability of network environments, you should **fully test the framework before integrating it**. +4. The author **is not responsible** for any issues that may arise from the use of this project. + +For full license details, see the [LICENSE](./LICENSE) file. + diff --git a/README.md b/README.md index 6a5cd55..7f8ef63 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,36 @@ # ios-async-socket-explorer +> [English Version (简要英文版入口) → Click here](./README.en.md) ![GitHub stars](https://img.shields.io/github/stars/CodeAcmen/ios-async-socket-explorer?style=social) ![Platform](https://img.shields.io/badge/platform-iOS-blue.svg) ![License](https://img.shields.io/badge/license-MIT-green.svg) -> 基于CocoaAsyncSocket构建的企业级iOS通信框架,提供高性能、可靠的IM底层支持。 +> 企业级 iOS TCP 通信框架,专为高并发、弱网环境、模块化架构而设计。 ## 概述 -ios-async-socket-explorer 是一个生产级TCP通信框架,来源于即时通讯领域实际工作经验(**已脱敏**)。展示了从**小型项目单 TCP 架构**,逐步演进为适用于中大型项目**多路复用架构**的过程,包含协议设计、架构解耦、高并发优化等核心实践。 +`ios-async-socket-explorer` 是一套基于 CocoaAsyncSocket 封装的生产级通信框架,源自真实企业级 IM 项目实践,致力于提升 iOS 在弱网、高并发场景下的 TCP 通信稳定性、可维护性和扩展能力。 **主要特性:** -- 支持峰值3k+并发连接的高性能架构,日均稳定处理10万+消息量 -- 完善的弱网环境优化策略,包含指数退避重连算法和自适应心跳 -- TLS加密与自定义二进制协议,保障通信安全性 -- 企业级VIPER分层架构设计,单元测试覆盖率>90% -- 丰富的监控指标和全链路追踪,确保系统可观测性 +- 支持 **3000+并发连接**,**日均处理10w+消息** +- 实现 **TLV二进制协议 + CRC32校验 + ACK确认机制** +- 搭载 **RTT自适应心跳**、**指数退避重连**,支持复杂弱网环境 +- 企业级 **VIPER分层架构设计**,单元测试覆盖率>85% +- 丰富的**监控指标和全链路追踪**,确保系统可观测性 + +> 已被用于 B2B IM 服务、物联网通信、弱网移动端场景评估 + +## 为什么选型 CocoaAsyncSocket? + +尽管 iOS 生态已有多种通信方案(如 Starscream、NSURLSession WebSocket 等),但: + +| 选型因素 | 原因 | +|----------|------| +| 高并发 + 底层控制 | CocoaAsyncSocket 支持底层 socket 原生封装,适合定制协议 | +| 企业部署场景 | 兼容 TLS、Socket KeepAlive、链路监控等安全与连接策略 | +| 可控性强 | 相比 WebSocket,更灵活地实现连接复用、消息确认、重传策略 | +| 跨项目适配 | Objective-C 封装 + Swift 调用,适配多技术栈客户端项目 | + +--- ## 🛠️ 技术栈