Skip to content
Proyectos

Acerca de

Biblioteca UDP ligera y fiable para Mono y .NET

Sistemas e infraestructura

Cómo se miden estas cifras

What you can do

  • 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

Crecimiento de estrellas medido

in 24h
-2
in 7 days
+4
in 15 days
+5
in 1 month
+11

Cambios netos en períodos que se solapan, no totales diarios. Los datos no disponibles se dejan en blanco. Las estrellas indican interés, no calidad.

README.md

Original

LiteNetLib 2

Lite reliable UDP library for .NET Standard 2.1 (Mono, .NET)

Made in Ukraine

HighLevel API Part: LiteEntitySystem

Matrix chat: Matrix

Discord chat: Discord

OLD BRANCH (and examples) for 1.x

Little Game Example on Unity

Documentation

Build

NuGet NuGet NuGet NuGet

Release builds GitHub (pre-)release

DLL build from 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 (reliable 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 (using separate socket for performance)
  • Connection statistics
  • 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 2021.2 (Desktop platforms, Android, iOS, Switch)

Support developer

  • "Buy Me A Coffee"

  • USDT TRC20: TE5eBgq8SyEeZFKtCgZG9GwL34sANmbc67

  • USDT BEP20/ERC20: 0x4c0D6DC76c6A6B354f5ec6c9e51893fFC6510d1E

  • Bitcoin: bc1q269ecs8r5vnrum5qr5j98sdglhnxlulv0f6egd

Unity notes!!!

  • Minimal supported Unity is 2021.2. For older Unity versions use 1.x library versions
  • Always use library sources or OpenUPM package instead of precompiled DLL files ( because there are platform specific #ifdefs and workarounds for unity bugs )

Usage samples

Client

var listener = new EventBasedNetListener();
var client = new NetManager(listener);
client.Start();
client.Connect("localhost" /* host IP or name */, 9050 /* port */, "SomeConnectionKey" /* text key or NetDataWriter */);
listener.NetworkReceiveEvent += (fromPeer, dataReader, channel, 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

var listener = new EventBasedNetListener();
var 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
    var 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();

Broadcast discovery

Set BroadcastReceiveEnabled on a manager that should receive broadcast packets. They are reported through OnNetworkReceiveUnconnected with UnconnectedMessageType.Broadcast. With multiple network interfaces, bind the manager to the local IPv4 address of the interface to use instead of calling Start(port):

using System.Net;
using LiteNetLib;

var listener = new EventBasedNetListener();
var manager = new NetManager(listener)
{
    BroadcastReceiveEnabled = true,
    IPv6Enabled = false
};

var localAddress = IPAddress.Parse("192.168.1.10"); // address assigned to the desired interface
manager.Start(localAddress, IPAddress.IPv6Any, 9050);

Use the same address-specific Start overload for a sender. To use multiple IPv4 interfaces, create a manager bound to each interface address.

Explorar proyectos relacionados

Cargando…