Skip to content

A managed wrapper for ENet UDP Networking Library written in C#

License

Notifications You must be signed in to change notification settings

moien007/ENet.Managed

Repository files navigation

Discord ENet version Nuget Nuget (with prereleases) Build status

ENet.Managed

ENet is cross-platform reliable UDP networking library written in C and ENet.Managed is an unofficial, managed wrapper for ENet available for .NET and it supports specific set of platforms. You can checkout ENet's repo here.

Quick start (Usage)

Take a look at examples folder.

Features

  • Supports AnyCPU targets
  • Supports IPv6
  • Provides async-await interface.
  • It's cross-platform via .NET Standard
  • It's available via NuGet package manager. (Here)
  • You can set custom:
    • compression method (not enabled by default, recommended to specify a compressor using CompressWith*)
    • checksum algorithm (not enabled by default, recommended to specify a checksum using ChecksumWith*)
    • heap allocator (by default ManagedENet forces ENet to use a custom allocator which is faster than malloc, take a look at ENetManagedAllocator.cs)
  • Takes advantage of Span<byte> and friends to reduce GC allocations.
  • Provides nearly all features of ENet via managed API.

Benchmarks

You can see how ENet performs compared to other libraries by taking look at these benchmarks.
Benchmarks for the wrapper itself are not available yet but it should have near native performance when optimizations are enabled.

Supported platfroms

Platform\Arch X86 X86_64 ARM32 ARM64
Windows Yes Yes Yes -
Linux - Yes Yes Yes
Mac - Yes - -

Linux binaries are built and statically linked against MUSL.

Notes

  • This wrapper deploys ENet binaries to OS's temp folder and dynamically loads them, you can alter this behavior using ENetStartupOptions or by manually initializing ENet using LibENet class.
  • ENet binaries are built from https://github.com/moien007/enet
  • ENet's checksum feature is disabled by default, it is highly recommended to use checksum to avoid receiving damaged packets.
    • ChecksumWithCRC32 enables ENet's builtin checksum feature.
  • In case of consuming custom version of ENet you have to sync the data structures offsets with the wrapper.
  • ENetPeer.DisconnectNow method will not generate ENetEventType.Disconnect.
  • If you use SetUserData extension methods you have to call UnsetUserData when you done, otherwise memory leak will happen.
  • You can use ENetPooledAllocator in case if you want to make ENet use pooled buffers to reduce allocations.

Contribution

You can contribute by reporting bugs and making pull requests.

License

MIT open-source license.

About

A managed wrapper for ENet UDP Networking Library written in C#

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages