{"id":16210021,"url":"https://github.com/bian-sh/unity-async-await-tcp","last_synced_at":"2025-03-19T08:31:16.572Z","repository":{"id":53838335,"uuid":"244569490","full_name":"Bian-Sh/Unity-async-await-tcp","owner":"Bian-Sh","description":"This is an async/await tcp communication (client and server  inside)  in unity.simple yet powerful！","archived":false,"fork":false,"pushed_at":"2024-04-13T20:45:32.000Z","size":51901,"stargazers_count":54,"open_issues_count":0,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-17T05:21:55.145Z","etag":null,"topics":["circularbuffer","remote-control","socket","tcp","tcp-client","tcp-server","unity","video-player"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Bian-Sh.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2020-03-03T07:28:14.000Z","updated_at":"2025-03-12T15:06:12.000Z","dependencies_parsed_at":"2022-08-13T03:00:45.180Z","dependency_job_id":"f16ef772-e1b3-43f3-84bf-e824662d277e","html_url":"https://github.com/Bian-Sh/Unity-async-await-tcp","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bian-Sh%2FUnity-async-await-tcp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bian-Sh%2FUnity-async-await-tcp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bian-Sh%2FUnity-async-await-tcp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Bian-Sh%2FUnity-async-await-tcp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Bian-Sh","download_url":"https://codeload.github.com/Bian-Sh/Unity-async-await-tcp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244389859,"owners_count":20445017,"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":["circularbuffer","remote-control","socket","tcp","tcp-client","tcp-server","unity","video-player"],"created_at":"2024-10-10T10:34:50.580Z","updated_at":"2025-03-19T08:31:11.561Z","avatar_url":"https://github.com/Bian-Sh.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unity Async Await TCP\n\n[中文](#1-简要说明)\n\n\u003e **Notice:** If you enjoy this repository and plan to use it, please consider using [TinyRPC](https://github.com/Bian-Sh/TinyRPC) instead!\n\n# 1. Description\n\n1. Base on async/await(TAP) syntax sugar.\n2. This Demo is a Remote Video Controller base on tcp , support play, pause, and stop command, and can read the remarks of MP4 file as well.\n3. Environment：Windows10 \u0026 Unity 2019.2.12f1\n4. Circularbuffer and a simple packet strategy (header + content) inside for avoiding message segmentation those caused by hard-coded buffer size.\n6. Disconnection notification, not the best maybe, but at least there is.\n7. Friendly reminder: Task will open threads on demand. It is a good habit to always pay attention to context thread id, **API**:`` System.Threading.Thread.CurrentThread.ManagedThreadId``, to avoid exceptions caused by using Unity components in non-main threads.\n\n# 2. Project structure\n\n\u003e Controller\n\n- This is a TCP client\n- The remote controller of the video player realizes the acquisition of the playlist from the server, and the playback, pause, and stop of the video\n\n\u003e Player\n\n- This is the TCP server\n- Video player based on UnityEngine.Video.VideoPlayer\n- Realized getting file playlist and media file description from SteamingAssets \n- Media file description information is obtained using Interop.Shell32.dll\n- This demo provides a test video, but please do not use it for commercial purposes\n\n\u003e Common\n\n- Including communication message data model, simple event system, UnitySynchronizationContext extension\n- The common components of the client and the server managed in the form of UnityPackage facilitate the synchronization of the modification of the message data model at both ends.\n- network module \n\n\n# 3. Demonstrate\n\n- you can open several controller at a time.\n![](Doc/Demo.gif)\n\n\u003e**注意：** 如果您喜欢这个存储库并打算使用它，请考虑改用[TinyRPC](https://github.com/Bian-Sh/TinyRPC)！\n\n# 1. 简要说明\n1. 测试基于async/await(TAP) 模式下的TCP 通信。\n2. 这个Demo 是一个基于TCP通信的Remotecontroller for video player，实现了客户端控制服务端视频播放器的播放、暂停、停止，也实现了MP4文件备注信息的获取。\n3. Windows10 \u0026 Unity 2020.2.12f1  （使用较多新语法糖）\n4. 加入了环形缓冲器和简单的分包策略（记录包体长度的包头+包体）避免了写死缓存尺寸带来的消息被分割的异常。\n5. 加强了断线提醒，逻辑可能不是最优，但至少是有。\n6. 友情提示： Task 会按需开线程，时刻关注上下文线程是一个很好的习惯,**API**:``System.Threading.Thread.CurrentThread.ManagedThreadId`` ,避免在非主线程中使用Unity 组件导致的异常，在本示例中使用 LOOM 跨线程推送数据。\n\n# 2. 工程结构\n\u003e Controller\n- 这是TCP 客户端\n- 视频播放器的远程控制器，实现了从服务端获取播放列表、视频的播放、暂停、与停止\n\n\u003e Player \n- 这是TCP 服务端\n- 基于UnityEngine.Video.VideoPlayer 的视频播放器\n- 实现了从 SteamingAssets 获取文件播放列表和媒体文件描述\n- 媒体文件描述信息使用 Interop.Shell32.dll 获取\n- 本Demo提供了测试视频，但请勿用于商业用途\n\n\u003e Common \n- 包括通信消息数据模型，简易事件系统，UnitySynchronizationContext （Loom）扩展\n- 以UnityPackage 的形式管理的客户端与服务端的公共组件，方便了消息数据模型一端修改两端同步。\n- 以 UPM 包管理的 网络模块\n\n \n\n# 3. 演示\n- 可以开多个控制器\n![](Doc/Demo.gif)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbian-sh%2Funity-async-await-tcp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbian-sh%2Funity-async-await-tcp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbian-sh%2Funity-async-await-tcp/lists"}