LiteNetLib 0.9 indev
Lite reliable UDP library for .NET Framework 3.5, Mono, .NET Core 2.1, .NET Standard 2.0.
OLD BRANCH (and examples) for 0.8.x
Build
NuGet
![NuGet](https://camo.githubusercontent.com/38975f9fb4ebf6bd0c7ff03ad6f2299a170d79d5f3b0d99f1110f109712ef5e2/68747470733a2f2f696d672e736869656c64732e696f2f6e756765742f64742f4c6974654e65744c69622e737667)
Release builds ![GitHub (pre-)release](https://camo.githubusercontent.com/62d786d893d9ae5e7e7e758da354cb6e7f1663c6f6b0ec45d390f61c800c7f33/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f72656c656173652f526576656e616e74582f4c6974654e65744c69622f616c6c2e737667)
DLL build from master ![](https://camo.githubusercontent.com/6ad4c68a0e7e52923b2be8a89f13e420ea1802ba4af776f8f90f386fd85a8d38/68747470733a2f2f63692e6170707665796f722e636f6d2f6170692f70726f6a656374732f7374617475732f333534353031776e767873386b7568332f6272616e63682f6d61737465723f7376673d74727565)
( Warning! Master branch can be unstable! )
Donations are welcome and will help further development of this project.
https://www.buymeacoffee.com/revx
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)
- 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 (dual mode)
- Connection statisitcs
- Multicasting (for discovering hosts in local network)
- Unity support
- Supported platforms:
- Windows/Mac/Linux (.NET Framework, Mono, .NET Core)
- Android (Unity)
- iOS (Unity)
- UWP Windows 10 including phones
- Lumin OS (Magic Leap)
Unity notes!!!
- Always use library sources instead of precompiled DLL files ( because there are platform specific #ifdefs and workarounds for unity bugs )
Usage samples
Client
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) =>
{
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
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.EndPoint); // 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();