{"id":18565065,"url":"https://github.com/jenly1314/asocket","last_synced_at":"2025-08-19T05:32:34.351Z","repository":{"id":57720447,"uuid":"416000194","full_name":"jenly1314/ASocket","owner":"jenly1314","description":":globe_with_meridians: ASocket 是一个TCP/UDP协议的封装库，方便快速实现TCP的长连接与UDP的单播、组播、广播等相关通信","archived":false,"fork":false,"pushed_at":"2024-06-20T10:37:16.000Z","size":3952,"stargazers_count":55,"open_issues_count":0,"forks_count":14,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-12-08T05:30:18.285Z","etag":null,"topics":["android","datagrampacket","datagramsock","multicast","server-socket","socket","tcp","udp"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jenly1314.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-10-11T16:13:16.000Z","updated_at":"2024-11-21T05:07:26.000Z","dependencies_parsed_at":"2024-01-27T16:50:22.940Z","dependency_job_id":null,"html_url":"https://github.com/jenly1314/ASocket","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenly1314%2FASocket","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenly1314%2FASocket/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenly1314%2FASocket/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jenly1314%2FASocket/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jenly1314","download_url":"https://codeload.github.com/jenly1314/ASocket/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230326793,"owners_count":18209049,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","datagrampacket","datagramsock","multicast","server-socket","socket","tcp","udp"],"created_at":"2024-11-06T22:17:34.961Z","updated_at":"2025-08-19T05:32:34.335Z","avatar_url":"https://github.com/jenly1314.png","language":"Java","readme":"# ASocket\n\n[![MavenCentral](https://img.shields.io/maven-central/v/com.github.jenly1314/asocket?logo=sonatype)](https://repo1.maven.org/maven2/com/github/jenly1314/ASocket)\n[![JitPack](https://img.shields.io/jitpack/v/github/jenly1314/ASocket?logo=jitpack)](https://jitpack.io/#jenly1314/ASocket)\n[![CI](https://img.shields.io/github/actions/workflow/status/jenly1314/ASocket/build.yml?logo=github)](https://github.com/jenly1314/ASocket/actions/workflows/build.yml)\n[![Download](https://img.shields.io/badge/download-APK-brightgreen?logo=github)](https://raw.githubusercontent.com/jenly1314/ASocket/master/app/release/app-release.apk)\n[![API](https://img.shields.io/badge/API-16%2B-brightgreen?logo=android)](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)\n[![License](https://img.shields.io/github/license/jenly1314/ASocket?logo=open-source-initiative)](https://opensource.org/licenses/mit)\n\nASocket 是一个TCP/UDP协议的封装库，方便快速实现TCP的长连接与UDP的单播、组播、广播等相关通信。\n\n\u003e 通过 ASocket 统一管理 TCP/UDP 相关 Socket，让其适用于Android，在UI主线程调用和回调，在子线程异步处理消息的发送与接收\n\n## 效果展示\n![Image](GIF.gif)\n\n\u003e 你也可以直接下载 [演示App](https://raw.githubusercontent.com/jenly1314/ASocket/master/app/release/app-release.apk) 体验效果\n\n## 引入\n\n### Gradle:\n\n1. 在Project的 **build.gradle** 或 **setting.gradle** 中添加远程仓库\n\n    ```gradle\n    repositories {\n        //...\n        mavenCentral()\n    }\n    ```\n\n2. 在Module的 **build.gradle** 中添加依赖项\n    ```gradle\n    implementation 'com.github.jenly1314:asocket:1.0.0'\n    \n    ```\n\n## 使用\n\n### 特别说明\n\n#### 组播IP地址特别说明\n\u003e  多播的地址是特定的，D类地址用于多播。D类IP地址就是多播IP地址，即224.0.0.0至239.255.255.255之间的IP地址，并被划分为局部连接多播地址、预留多播地址和管理权限多播地址3类：\n\u003e  局部多播地址：在224.0.0.0～224.0.0.255之间，这是为路由协议和其他用途保留的地址，路由器并不转发属于此范围的IP包。\n\u003e  预留多播地址：在224.0.1.0～238.255.255.255之间，可用于全球范围（如Internet）或网络协议。\n\u003e  管理权限多播地址：在239.0.0.0～239.255.255.255之间，可供组织内部使用，类似于私有IP地址，不能用于Internet，可限制多播范围。\n\n### 代码示例\n```kotlin\n    //初始化一个ISocket的实现类（如：TCPClient、TCPServer、UDPClient、UDPServer、UDPMulticast）\n    val tcpClient = TCPClient(host,port)\n    //初始化ASocket\n    val aSocket = ASocket(tcpClient)\n    //设置状态监听\n    aSocket.setOnSocketStateListener(object : ISocket.OnSocketStateListener{\n        override fun onStarted() {\n\n        }\n    \n        override fun onClosed() {\n    \n        }\n    \n        override fun onException(e: Exception) {\n\n        }\n    \n    })\n    //设置接收消息监听\n    aSocket.setOnMessageReceivedListener { data -\u003e\n        //TODO 接收消息\n    }\n    //启动\n    aSocket.start()\n\n\n    //....\n    //发送消息\n    aSocket.write(data)\n\n```\n\n### 完整示例\n\n- TCPClient示例：[TCPClientActivity](app/src/main/java/com/king/asocket/app/tcp/TCPClientActivity.kt)\n\n- TCPServer示例：[TCPServerActivity](app/src/main/java/com/king/asocket/app/tcp/TCPServerActivity.kt)\n\n- UDPClient示例：[UDPClientActivity](app/src/main/java/com/king/asocket/app/udp/UDPClientActivity.kt)\n\n- UDPServer示例：[UDPServerActivity](app/src/main/java/com/king/asocket/app/udp/UDPServerActivity.kt)\n\n- UDPMulticast示例：[UDPMulticastActivity](app/src/main/java/com/king/asocket/app/udp/UDPMulticastActivity.kt)\n\n更多使用详情，请查看[Demo](app)中的源码使用示例或直接查看[API帮助文档](https://jitpack.io/com/github/jenly1314/ASocket/latest/javadoc/)\n\n## 相关推荐\n\n- [ANetty](https://github.com/jenly1314/ANetty) 基于Netty封装的Android链路通讯库，用以快速开发高性能，高可靠性的网络交互。在保证易于开发的同时还保证其应用的性能，稳定性和伸缩性。\n- [AWebSocket](https://github.com/jenly1314/AWebSocket) 基于okhttp封装的 WebSocket，简洁易用。\n\n## 版本日志\n\n#### v1.0.0：2021-10-13\n*  ASocket初始版本\n\n---\n\n![footer](https://jenly1314.github.io/page/footer.svg)\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjenly1314%2Fasocket","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjenly1314%2Fasocket","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjenly1314%2Fasocket/lists"}