Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/revenantx/litenetlib
Lite reliable UDP library for Mono and .NET
https://github.com/revenantx/litenetlib
cross-platform csharp dot-net mono network networking reliable-packets udp unity-3d
Last synced: about 1 month ago
JSON representation
Lite reliable UDP library for Mono and .NET
- Host: GitHub
- URL: https://github.com/revenantx/litenetlib
- Owner: RevenantX
- License: mit
- Created: 2016-01-15T18:28:35.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2024-09-03T07:57:24.000Z (2 months ago)
- Last Synced: 2024-10-12T15:02:58.501Z (about 1 month ago)
- Topics: cross-platform, csharp, dot-net, mono, network, networking, reliable-packets, udp, unity-3d
- Language: C#
- Homepage: https://revenantx.github.io/LiteNetLib/index.html
- Size: 8.34 MB
- Stars: 3,066
- Watchers: 152
- Forks: 495
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
README
# LiteNetLib
Lite reliable UDP library for .NET Standard 2.0 (Mono, .NET Core, .NET Framework)
[![Made in Ukraine](https://img.shields.io/badge/made_in-ukraine-ffd700.svg?labelColor=0057b7)](https://stand-with-ukraine.pp.ua)
**HighLevel API Part**: [LiteEntitySystem](https://github.com/RevenantX/LiteEntitySystem)
**Discord chat**: [![Discord](https://img.shields.io/discord/501682175930925058.svg)](https://discord.gg/FATFPdy)
[OLD BRANCH (and examples) for 0.9.x](https://github.com/RevenantX/LiteNetLib/tree/0.9)
[Little Game Example on Unity](https://github.com/RevenantX/NetGameExample)
[Documentation](https://revenantx.github.io/LiteNetLib/index.html)
## Build
### [NuGet](https://www.nuget.org/packages/LiteNetLib/) [![NuGet](https://img.shields.io/nuget/v/LiteNetLib?color=blue)](https://www.nuget.org/packages/LiteNetLib/) [![NuGet](https://img.shields.io/nuget/vpre/LiteNetLib)](https://www.nuget.org/packages/LiteNetLib/#versions-body-tab) [![NuGet](https://img.shields.io/nuget/dt/LiteNetLib)](https://www.nuget.org/packages/LiteNetLib/)
### [Release builds](https://github.com/RevenantX/LiteNetLib/releases) [![GitHub (pre-)release](https://img.shields.io/github/release/RevenantX/LiteNetLib/all.svg)](https://github.com/RevenantX/LiteNetLib/releases)
### [DLL build from master](https://ci.appveyor.com/project/RevenantX/litenetlib/branch/master/artifacts) [![](https://ci.appveyor.com/api/projects/status/354501wnvxs8kuh3/branch/master?svg=true)](https://ci.appveyor.com/project/RevenantX/litenetlib/branch/master)
( Warning! Master branch can be unstable! )## Features
* Lightweight
* Small CPU and RAM usage
* Small packet size overhead ( 1 byte for unreliable, 4 bytes for reliable packets )
* Simple connection handling
* Peer to peer connections
* Helper classes for sending and reading messages
* Multiple data channels
* Different send mechanics
* Reliable with order
* Reliable without order
* Reliable sequenced (realiable only last packet)
* Ordered but unreliable with duplication prevention
* Simple UDP packets without order and reliability
* Fast packet serializer [(Usage manual)](https://revenantx.github.io/LiteNetLib/articles/netserializerusage.html)
* Automatic small packets merging
* Automatic fragmentation of reliable packets
* Automatic MTU detection
* Optional CRC32C checksums
* UDP NAT hole punching
* NTP time requests
* Packet loss and latency simulation
* IPv6 support (using separate socket for performance)
* Connection statisitcs
* Multicasting (for discovering hosts in local network)
* Unity support
* Support for .NET8 optimized socket calls (much less gc)
* Supported platforms:
* Windows/Mac/Linux (.NET Framework, Mono, .NET Core, .NET Standard)
* Lumin OS (Magic Leap)
* Monogame
* Godot
* Unity 2018.3 (Desktop platforms, Android, iOS, Switch)
## Support developer
[!["Buy Me A Coffee"](https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png)](https://www.buymeacoffee.com/revx)## Unity notes!!!
* Minimal supported Unity is 2018.3. For older Unity versions use [0.9.x library](https://github.com/RevenantX/LiteNetLib/tree/0.9) versions
* Always use library sources instead of precompiled DLL files ( because there are platform specific #ifdefs and workarounds for unity bugs )## Usage samples
### Client
```csharp
EventBasedNetListener listener = new EventBasedNetListener();
NetManager client = new NetManager(listener);
client.Start();
client.Connect("localhost" /* host ip or name */, 9050 /* port */, "SomeConnectionKey" /* text key or NetDataWriter */);
listener.NetworkReceiveEvent += (fromPeer, dataReader, deliveryMethod, channel) =>
{
Console.WriteLine("We got: {0}", dataReader.GetString(100 /* max length of string */));
dataReader.Recycle();
};while (!Console.KeyAvailable)
{
client.PollEvents();
Thread.Sleep(15);
}client.Stop();
```
### Server
```csharp
EventBasedNetListener listener = new EventBasedNetListener();
NetManager server = new NetManager(listener);
server.Start(9050 /* port */);listener.ConnectionRequestEvent += request =>
{
if(server.ConnectedPeersCount < 10 /* max connections */)
request.AcceptIfKey("SomeConnectionKey");
else
request.Reject();
};listener.PeerConnectedEvent += peer =>
{
Console.WriteLine("We got connection: {0}", peer); // Show peer ip
NetDataWriter writer = new NetDataWriter(); // Create writer class
writer.Put("Hello client!"); // Put some string
peer.Send(writer, DeliveryMethod.ReliableOrdered); // Send with reliability
};while (!Console.KeyAvailable)
{
server.PollEvents();
Thread.Sleep(15);
}
server.Stop();
```