LiteNetwork Versions Save

A simple and fast .NET networking library compatible with .NET Standard 2, .NET 5, 6 and 7.

v2.4.0

3 months ago

➕ Added

  • .NET 8 support

❌ Removed

  • .NET 5 support

v2.3.0

9 months ago

➕Added

  • Add optimization and select byte order mode for header (PR #56)

v2.2.0

1 year ago

🔁Changes

  • Change LiteServer.OnError paramter from LiteConnection to TUser.

v2.1.0

1 year ago

➕Added

  • Add .NET 7 support.
  • Add support for IPAddress.Any in LiteServerOptions. (#54) (PR #55)
  • Add some missing XML comments.

🔁Changes

  • Add file scoped namespace.

v2.0.0

1 year ago

:boom: BREAKING CHANGES :boom:

Protocol

❌ Removed

  • Remove the LitePacketMode, LitePacketStream and ILitePacketStream interface and all its dependencies This removal affects the way the user handles packets on both LiteClient and LiteServerUser classes. Previously, we had:
public class User : LiteServerUser
{
    public override Task HandleMessageAsync(ILitePacketStream packet)
    {
    }
}

This code should be replaced with:

public class User : LiteServerUser
{
    public override Task HandleMessageAsync(byte[] packetBuffer)
    {
        // Use your own way to read the incoming packet buffer.
    }
}
  • Remove the LitePacket mechanism. The LitePacketStream will be kept to provide an alternative to the BinaryReader/Writer implementation. Note that the LitePacketStream uses a BinaryReader and BinaryWriter internally.
  • Remove the virtual ILitePacketStream CreatePacket(byte[] buffer) from LitePacketProcessor and its abstraction. No need for this method since we removed the ILitePacketStream interface. We will pass directly the raw packet buffer to the HandleMessageAsync method.

➕ Added

  • Add Send(byte[]) and Send(Stream) methods to LiteClient and LiteServerUser.
    • The Send(byte[]) sends a raw packet to the remote end point.
    • The Send(Stream) method sends the buffer contained in the given stream to the remote end point.

By providing these two options, the user is free to choose which technique to use to send its packet. It can use the native .NET BinaryWriter class or any other way to build its packet buffer.

using var stream = new MemoryStream();
using var packet = new BinaryWriter(stream);

packet.Write(42); // int32
packet.Write("Hello World!"); // string

byte[] buffer = packet.GetBuffer();

_user.Send(buffer); // byte[] overload
// or
_user.Send(packet); // Stream overload

LiteConnection

❌ Removed

  • Remove ILiteConnection abstraction.

➕ Added

  • Add LiteConnection with all basic information:
    • public Guid Id { get; }
    • public Socket? Socket { get: }
    • public abstract Task HandleMessageAsync(byte[] packetBuffer)
    • public virtual void Send(byte[] packetBuffer)
    • public virtual void Send(Stream packetStream)

LiteServer

❌ Removed

  • Rework the ILiteServer abstraction to be more straightforward and simple.
  • Remove generic mechanism and contraints on ILiteServer.
  • The following properties and methods have been removed from ILiteServer :
    • IEnumerable<TUser> ConnectedUsers { get; }
    • TUser? GetUser(Guid userId)
    • bool TryGetUser(Guid userId, out TUser? user)
    • void Start()
    • void Stop()
    • Task StopAsync(CancellationToken cancellationToken)
    • void DisconnectUser(Guid userId)
    • void SendTo(TUser user, ILitePacketStream packet)
    • void SendTo(IEnumerable<TUser> users, ILitePacketStream packet)
    • void SendToAll(ILitePacketStream packet)
  • Remove the synchronous Start(), Stop() and StopAsync(CancellationToken cancellationToken) methods from LiteServer`.
  • Remove default LiteServer constructor public LiteServer(LiteServerOptions options)
  • Remove ILiteBuilder AddLiteServer<TLiteServerUser>

➕ Added

  • Add a LiteServerContext mechanism to allow interaction with the server through the the LiteServerUser class.
  • Add IEnumerable<LiteConnection> Users { get; } to ILiteServer abstraction.
  • Add void DisconnectUser(Guid userId); to ILiteServer abstraction.
  • Add void DisconnectUser(LiteConnection connection); to ILiteServer abstraction.
  • Add void SendTo(LiteConnection connection, byte[] packet); to ILiteServer abstraction.
  • Add void SendTo(IEnumerable<LiteConnection> connections, byte[] packet); to ILiteServer abstraction.
  • Add void SendToAll(byte[] packet); to ILiteServer abstraction.

🔁 Changes

  • Changed IEnumerable<TUser> ConnectedUsers { get; } to IEnumerable<LiteConnection> Users { get; }
  • Changed void SendTo(TUser user, byte[] packet) to void SendTo(LiteConnection connection, byte[] packet)
  • Changed void SendTo(IEnumerable<TUser> users, byte[] packet) to void SendTo(IEnumerable<LiteConnection> connections, byte[] packet)
  • Replace SendTo(TUser user, ILitePacketStream packet) with void SendTo(TUser user, byte[] packet)
  • Replace void SendTo(IEnumerable<TUser> users, ILitePacketStream packet) with SendTo(IEnumerable<TUser> users, byte[] packet)
  • Replace void SendToAll(ILitePacketStream packet) with void SendToAll(byte[] packet)

Hosting

  • Replace ILiteBuilder AddLiteServer<TLiteServer, TLiteServerUser> by ILiteBuilder AddLiteServer<TLiteServer> Pass directly a LiteServer implementation to the builder.
  • Replace ILiteBuilder AddLiteServer<TLiteServer, TLiteServerImplementation, TLiteServerUser> by ILiteBuilder AddLiteServer<TLiteServer, TLiteServerImplementation> If the user wants to add an extra interface to its LiteServer he can also register the interface and the implementation together in the service provider.

LiteServerUser

❌ Removed

  • Remove Id, Socket properties, HandleMessageAsync, Send(byte[]) and Send(Stream) as they were moved to LiteConnection base class.

LiteClient

❌ Removed

  • Remove the ILiteClient abstraction. Keeping it simple and extendable.
  • Remove Id, Socket properties, HandleMessageAsync, Send(byte[]) and Send(Stream) as they were moved to LiteConnection base class.

Hosting

  • Remove default ILiteBuilder AddLiteClient() method.

Misc

  • Fix issues related to task processing
  • Fix potential nullable references
  • Removed /// <inheritdoc /> documentation comments.
  • Added samples to show how to create a custom packet reader/writer.
  • Update Microsoft.Extensions.DependencyInjection minimum version to 3.1.20
  • Update Microsoft.Extensions.Hosting.Abstractions minimum version to 3.1.20
  • Update Microsoft.Extensions.Logging.Abstractions minimum version to 3.1.20

v2.0.0-rc.6

2 years ago

LiteServer

➕ Added

  • Add a LiteServerContext mechanism to allow interaction with the server through the the LiteServerUser class.
  • Add IEnumerable<LiteConnection> Users { get; } to ILiteServer abstraction.
  • Add void DisconnectUser(Guid userId); to ILiteServer abstraction.
  • Add void DisconnectUser(LiteConnection connection); to ILiteServer abstraction.
  • Add void SendTo(LiteConnection connection, byte[] packet); to ILiteServer abstraction.
  • Add void SendTo(IEnumerable<LiteConnection> connections, byte[] packet); to ILiteServer abstraction.
  • Add void SendToAll(byte[] packet); to ILiteServer abstraction.

🔁 Changes

  • Changed IEnumerable<TUser> ConnectedUsers { get; } to IEnumerable<LiteConnection> Users { get; }
  • Changed void SendTo(TUser user, byte[] packet) to void SendTo(LiteConnection connection, byte[] packet)
  • Changed void SendTo(IEnumerable<TUser> users, byte[] packet) to void SendTo(IEnumerable<LiteConnection> connections, byte[] packet)

v2.0.0-rc.5

2 years ago

LiteClient

Host

🔁Changes

  • Fixed hosted service registration for abstraction and implementation method.

v2.0.0-rc.4

2 years ago

LiteServer

Hosting

🔁Changes

  • Fixed hosted service registration.

LiteClient

Host

🔁Changes

  • Fixed hosted service registration.

v2.0.0-rc.3

2 years ago

LiteServer

Hosting

###🔁Changes

  • Register implementation in service collection when registering as server with an abstraction. Thus, the developer can retrieve the abstraction or the implementation.

v2.0.0-rc.2

2 years ago

Protocol

🔁 Changes

  • Fix typo on ILitePacketProcessor.AppendHeader() method.