Skip to main content

MagicOnion

Unified Realtime/API framework for .NET platform and Unity.

https://github.com/Cysharp/MagicOnion

About MagicOnion

MagicOnion is a modern RPC framework for .NET platform that provides bi-directional real-time communications such as SignalR and Socket.io and RPC mechanisms such as WCF and web-based APIs.

This framework is based on gRPC, which is a fast and compact binary network transport for HTTP/2. However, unlike plain gRPC, it treats C# interfaces as a protocol schema, enabling seamless code sharing between C# projects without .proto (Protocol Buffers IDL).

image

Interfaces are schemas and provide API services, just like the plain C# code

image

Using the StreamingHub real-time communication service, the server can broadcast data to multiple clients

MagicOnion uses MessagePack for C# to serialize call arguments and return values. .NET primitives and other complex types that can be serialized into MessagePack objects. See MessagePack for C# for details about serialization.

Use Cases

MagicOnion can be adopted or replaced in the following use cases:

  • RPC services such as gRPC, used by Microservices, and WCF, commonly used by WinForms/WPF
  • API services such as ASP.NET Core Web API targeting various platforms and clients such as Windows WPF applications, Unity games, .NET for iOS, Android, and .NET MAUI
  • Bi-directional real-time communication such as Socket.io, SignalR, Photon and UNet

MagicOnion supports API services and real-time communication, making it suitable for various use cases. You can use either of these features separately, but configurations that combine both are also supported.

Technology stack

MagicOnion is built on top of various modern technologies.

The server is implemented on a gRPC server (grpc-dotnet) on ASP.NET Core, utilizing the features of ASP.NET Core and Grpc.AspNetCore.Server. This includes DI, logging, metrics, and Hosting API.

Transport uses the HTTP/2 protocol and utilizes binary messaging with gRPC. Instead of Protocol Buffers, which are commonly used in gRPC, it adopts MessagePack, which has high affinity and expressive power with .NET.

The client supports not only .NET runtime but also Unity game engine runtime. It uses a gRPC client (grpc-dotnet) based on .NET built-in HttpClient on these runtimes and builds the MagicOnion client library on top of it.