LiteNetLib

Lite reliable UDP library for Mono and .NET

Github星跟踪图

LiteNetLib 0.9 indev

Lite reliable UDP library for .NET Framework 3.5, Mono, .NET Core 2.1, .NET Standard 2.0.

STABLE BRANCH (and examples) for 0.8.x

Discord

Little Game Example on Unity

Documentation

Build

NuGet NuGet NuGet

Release builds GitHub (pre-)release

DLL build from master

( Warning! Master branch can be unstable! )

Donations are welcome and will help further development of this project.

Bountysource

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 (need DEBUG or STATS_ENABLED flag)
  • 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.PeersCount < 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();

NetManager settings description

  • UnconnectedMessagesEnabled
    • enable messages receiving without connection. (with SendUnconnectedMessage method)
    • default value: false
  • NatPunchEnabled
    • enable NAT punch messages
    • default value: false
  • UpdateTime
    • library logic update (and send) period in milliseconds
    • default value: 15 msec.
  • PingInterval
    • Interval for latency detection and checking connection
    • default value: 1000 msec.
  • DisconnectTimeout
    • if client or server doesn't receive any packet from remote peer during this time then connection will be closed
    • (including library internal keepalive packets)
    • default value: 5000 msec.
  • SimulatePacketLoss
    • simulate packet loss by dropping random amout of packets. (Works only in DEBUG mode)
    • default value: false
  • SimulateLatency
    • simulate latency by holding packets for random time. (Works only in DEBUG mode)
    • default value: false
  • SimulationPacketLossChance
    • chance of packet loss when simulation enabled. value in percents.
    • default value: 10 (%)
  • SimulationMinLatency
    • minimum simulated latency
    • default value: 30 msec
  • SimulationMaxLatency
    • maximum simulated latency
    • default value: 100 msec
  • BroadcastEnabled
    • Allows receive Broadcast packets
    • default value: false
  • ReconnectDelay
    • delay betwen connection attempts
    • default value: 500 msec
  • MaxConnectAttempts
    • maximum connection attempts before client stops and call disconnect event.
    • default value: 10
  • UnsyncedEvents
    • Warning! Use this only when you know what are you doing, and sync data manually
    • Events automatically will be called without PollEvents method from socket recieve thread
    • default value: false

主要指标

概览
名称与所有者RevenantX/LiteNetLib
主编程语言C#
编程语言C# (语言数: 2)
平台
许可证MIT License
所有者活动
创建于2016-01-15 18:28:35
推送于2025-02-02 16:22:46
最后一次提交2025-01-29 13:07:00
发布数50
最新版本名称1.3.3 (发布于 2025-02-02 18:15:43)
第一版名称0.2.1 (发布于 )
用户参与
星数3.2k
关注者数151
派生数504
提交数1.3k
已启用问题?
问题数417
打开的问题数11
拉请求数132
打开的拉请求数0
关闭的拉请求数24
项目设置
已启用Wiki?
已存档?
是复刻?
已锁定?
是镜像?
是私有?