GithubHelp home page GithubHelp logo

bian-sh / unity-async-await-tcp Goto Github PK

View Code? Open in Web Editor NEW
52.0 2.0 8.0 50.68 MB

This is an async/await tcp communication (client and server inside) in unity.simple yet powerful!

C# 99.09% JavaScript 0.84% Objective-C++ 0.07%
socket tcp tcp-server tcp-client circularbuffer remote-control video-player unity

unity-async-await-tcp's Introduction

Unity Async Await TCP

中文

Notice: If you enjoy this repository and plan to use it, please consider using TinyRPC instead!

1. Description

  1. Base on async/await(TAP) syntax sugar.
  2. 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.
  3. Environment:Windows10 & Unity 2019.2.12f1
  4. Circularbuffer and a simple packet strategy (header + content) inside for avoiding message segmentation those caused by hard-coded buffer size.
  5. Disconnection notification, not the best maybe, but at least there is.
  6. 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.

2. Project structure

Controller

  • This is a TCP client
  • 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

Player

  • This is the TCP server
  • Video player based on UnityEngine.Video.VideoPlayer
  • Realized getting file playlist and media file description from SteamingAssets
  • Media file description information is obtained using Interop.Shell32.dll
  • This demo provides a test video, but please do not use it for commercial purposes

Common

  • Including communication message data model, simple event system, UnitySynchronizationContext extension
  • 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.
  • network module

3. Demonstrate

  • you can open several controller at a time.

注意: 如果您喜欢这个存储库并打算使用它,请考虑改用TinyRPC

1. 简要说明

  1. 测试基于async/await(TAP) 模式下的TCP 通信。
  2. 这个Demo 是一个基于TCP通信的Remotecontroller for video player,实现了客户端控制服务端视频播放器的播放、暂停、停止,也实现了MP4文件备注信息的获取。
  3. Windows10 & Unity 2020.2.12f1 (使用较多新语法糖)
  4. 加入了环形缓冲器和简单的分包策略(记录包体长度的包头+包体)避免了写死缓存尺寸带来的消息被分割的异常。
  5. 加强了断线提醒,逻辑可能不是最优,但至少是有。
  6. 友情提示: Task 会按需开线程,时刻关注上下文线程是一个很好的习惯,API:System.Threading.Thread.CurrentThread.ManagedThreadId ,避免在非主线程中使用Unity 组件导致的异常,在本示例中使用 LOOM 跨线程推送数据。

2. 工程结构

Controller

  • 这是TCP 客户端
  • 视频播放器的远程控制器,实现了从服务端获取播放列表、视频的播放、暂停、与停止

Player

  • 这是TCP 服务端
  • 基于UnityEngine.Video.VideoPlayer 的视频播放器
  • 实现了从 SteamingAssets 获取文件播放列表和媒体文件描述
  • 媒体文件描述信息使用 Interop.Shell32.dll 获取
  • 本Demo提供了测试视频,但请勿用于商业用途

Common

  • 包括通信消息数据模型,简易事件系统,UnitySynchronizationContext (Loom)扩展
  • 以UnityPackage 的形式管理的客户端与服务端的公共组件,方便了消息数据模型一端修改两端同步。
  • 以 UPM 包管理的 网络模块

3. 演示

  • 可以开多个控制器

unity-async-await-tcp's People

Contributors

bian-sh avatar sunhaida avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

unity-async-await-tcp's Issues

How to use this repo to download m3u8 URL and save to local disk drive?

Hello:
I happen to find your repo, and it seems to be interesting. However, as I have no experience on Unity,
I can’t figure out yet how to download multiple M3U8 videos and save to local hard drive.
For example, I have the following 2 M3U8 videos in the URL:
http://demo.unified-streaming.com/video/tears-of-steel/tears-of-steel.ism/.m3u8
http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8
I want to launch 2 clients to download them at the same time, when finished, I want to save the files as local files: C:\1.mp4 and C:\2.mp4 and stop or dispose the client.
Please show me how I can do this with C#.
By the way, I am using Windows 10 Version 21H1, and Visual Studio 2019 Version 16.10.4.
Thanks,

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.