It used in some game projects already. And works very stable and fast.
You can use it without Unity3d (just Mono or .NET) that sometimes very useful for servers. It doesn’t use LINQ or Reflection (except in NetSerializer). And doesn’t use native code.
I like how simple this looks. I’ve used a number of other libraries (including lidgren multiple times) in Unity, but my choices are limited this time since this project needs to have no paid assets in it. I was going to go with Lidgren again, but I’ll give this a shot first.
Can you provide any comparison/benchmark with Lidgren Network? It can be very interesting to compare them.
I will give it a shot if it results more stable and fast than Lidgren lib!
I created this library for my FPS multiplayer game because lidgren-network have bugs in Reliable channel (drop packets and reordering)
About performance: In last update i improved and tested transfer speed. Result - 100 mbytes per second on local socket with ReliableInOrder packets.
From RFC
An SNTP client implementing the on-wire protocol has a single server
and no dependent clients. It can operate with any subset of the NTP
on-wire protocol, the simplest approach using only the transmit
timestamp of the server packet and ignoring all other fields.
However, the additional complexity to implement the full on-wire
protocol is minimal so that a full implementation is encouraged.
That exactly what i do. Only timestamp is used. But it works with any servers)
RevenantX, I am attempting to use LiteNetLib to communicate between a server built in Unity and a stand alone server written in C#. I’ve been able to communicate between two Unity instances using LiteNetLib but cannot get a Unity instance to connect to a stand alone LiteNetLib server. Using the code shown below on the server the only response in the console dialog is “Database Server status true port 5000”. It appears that there is no data being received from the Unity client. I’ve tried disabling firewalls etc without improvement. The same client that I’m using connects to another Unity instance just fine. Any suggestions would be greatly appreciated.
using System;
using System.Threading;
using LiteNetLib;
using LiteNetLib.Utils;
class Program
{
static void Main(string[] args)
{
int port = 5000;
TestNet tn;
EventBasedNetListener listener = new EventBasedNetListener();
NetServer server = new NetServer(listener, 10, "LNDB Server");
bool serverStat = server.Start(port);
server.DiscoveryEnabled = true;
server.UnconnectedMessagesEnabled = true;
tn = new TestNet(server);
Console.WriteLine("Database Server status" + serverStat + " port " + port);
listener.PeerConnectedEvent += peer =>
{
Console.WriteLine("We got connection: {0}", peer.EndPoint); // Show peer ip
NetDataWriter writer = new NetDataWriter(); // Create writer class
writer.Put(1); // Put some string
peer.Send(writer, SendOptions.ReliableOrdered); // Send with reliability
listener.NetworkReceiveEvent += tn.OnServerReceive; // Connect the OnNetworkReceive callback
};
listener.NetworkReceiveUnconnectedEvent += tn.OnNetworkReceiveUnconnected;
tn.Poller();
}
}
class TestNet
{
private NetServer _netServer;
public TestNet(NetServer ns)
{
_netServer = ns;
}
public void Poller()
{
while (true)
{
_netServer.PollEvents();
Thread.Sleep(15);
}
}
public void OnServerReceive(NetPeer peer, NetDataReader reader)
{
Console.WriteLine("[SERVER] Received data");
}
public void OnNetworkReceiveUnconnected(NetEndPoint remoteEndPoint, NetDataReader reader, UnconnectedMessageType messageType)
{
Console.WriteLine("[SERVER] Received discovery request");
if (messageType == UnconnectedMessageType.DiscoveryRequest)
{
_netServer.SendDiscoveryResponse(new byte[] { 1 }, remoteEndPoint);
}
}
}
Do you use same versions of LiteNetLib on client and server? (in repo UnityExample there is outdated lib, use from Release pages)
P.S. And better set UpdateTime before Start() call
RevenantX, I copied over the dll from the stand alone and that worked. As I write this I realize that I didn’t try the UpdateTime but will add that too. Thanks for suggesting to look at the library versions.
Looks like a great library. Looking forward to working with it.