TriaStudios.NetworkLib.Core
2.1.0
dotnet add package TriaStudios.NetworkLib.Core --version 2.1.0
NuGet\Install-Package TriaStudios.NetworkLib.Core -Version 2.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TriaStudios.NetworkLib.Core" Version="2.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TriaStudios.NetworkLib.Core" Version="2.1.0" />
<PackageReference Include="TriaStudios.NetworkLib.Core" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TriaStudios.NetworkLib.Core --version 2.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: TriaStudios.NetworkLib.Core, 2.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TriaStudios.NetworkLib.Core@2.1.0
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TriaStudios.NetworkLib.Core&version=2.1.0
#tool nuget:?package=TriaStudios.NetworkLib.Core&version=2.1.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Socket packages lib
Setting new server/client
- Create session data
public class SessionData
{
//Data
}
- Create custom session
public class CustomSession : NetworkSession
{
public SessionData Data { get; } = new GameSessionData();
}
- Build server
public class Program
{
private static readonly IPEndPoint Ip = IPEndPoint.Parse("127.0.0.1:1234");
public static async Task Main(string[] args)
{
var builderSocket = NetworkSocket<GameSession>.Builder()
.BindAddress(Ip)
.AddLogger((layer, s) => Console.WriteLine($"[{DateTime.Now}] [{layer.ToString().ToUpper()}] {s}"))
.AddConnectHandler((session, services) =>
{
var instance = services.GetInstance<ILogger>();
instance.Debug(LoggerLayer.Debug, $"Connected {session.ToInfo.SourceType} with address {session.ToInfo.EndPoint}");
})
.AddDisconnectHandler((session, services) =>
{
var instance = services.GetInstance<ILogger>();
instance.Debug(LoggerLayer.Debug, $"Disconnected {session.ToInfo.SourceType} with address {session.ToInfo.EndPoint}");
})
.AddPipeline(builder =>
{
// If you use encryption (RSA) it is useless to use compression
// because encryption text is not to be able to compress more than it is.
builder.UseEncryption();
builder.UseCompression(CompressionLevel.Optimal);
// Custom middlewares
builder.Use(service => new CustomMiddleware1(service));
builder.Use<CustomMiddleware2>();
});
// Build and run server from socket builder
var server = builderSocket
// You can register connect/disconnect handlers with IoCService
.RegisterConnectHandler((session, service) =>
service.GetInstance<HelloWorldFactory>().Send(session))
.BuildServer();
await server.RunAsync();
}
}
- Build client
You can build client right like server.
public class Program
{
private static readonly IPEndPoint Ip = IPEndPoint.Parse("127.0.0.1:1234");
public static async Task Main(string[] args)
{
// ... the same creator like server ...
var client = builderSocket.BuildClient();
await client.RunAsync();
}
}
- Create custom dependencies
/// <summary>
/// All dependencies are singleton by default!
/// </summary>
[Dependency]
[OrderLoad(100)]
public class Service1 : IoCBehaviour
{
private readonly ILogger _logger;
public override void Start()
{
_logger.Debug(LoggerLayer.Info, "Here you can run background processes");
}
}
[Dependency(DependencyLifetime.Transient)]
public class Service2
{
// You can pass dependencies from IoC like that
private readonly Service1 _hostedService;
}
- Create custom middlewares
public class CustomMiddleware1 : IMiddleware
{
private readonly IoCService _ioCService;
public CustomMiddleware1(IoCService ioCService)
{
_ioCService = ioCService;
}
public byte[] Forward(NetworkSession session, byte[] data)
{
return data;
}
public byte[] Backward(NetworkSession session, byte[] data)
{
return data;
}
}
public class CustomMiddleware2 : IMiddleware
{
public byte[] Forward(NetworkSession session, byte[] data)
{
return data;
}
public byte[] Backward(NetworkSession session, byte[] data)
{
return data;
}
}
How do new package create?
- Add new type and number of package.
public enum PackageType
{
// ...
HelloWorldType = 16,
// ...
}
- Create model class.
[PackagePack((short)PackageType.HelloWorldType)]
public class HelloWorldModel
{
public InnerStructure InnerStructure { get; set; }
}
[PackagePack]
public class InnerStructure
{
public int Number { get; set; }
}
- Create handler
/// <summary>
/// Class inheriting from Handler is automatic TRANSIENT dependency!
/// It is no need to write [Dependency(DependencyLifetime.Transient)]
/// </summary>
public class HelloWorldHandler : Handler<HelloWorldModel, GameSession>
{
private readonly ILogger _logger;
protected override void Handle(GameSession clientData, HelloWorldModel model)
{
_logger.Debug(LoggerLayer.Info, "Here you can handle package and send other packages backwards");
_logger.Debug(LoggerLayer.Info, $"Receive message from {clientData.ToInfo.EndPoint}");
// property ConnectedSessions can help you for handling package on server side
}
}
- Create factory
[Dependency]
public class HelloWorldFactory
{
private readonly ILogger _logger;
public void Send(GameSession gameSession)
{
_logger.Debug(LoggerLayer.Info, $"Send message from {gameSession.FromInfo.EndPoint} to {gameSession.ToInfo.EndPoint}");
gameSession.Send(new HelloWorldModel
{
InnerStructure = new InnerStructure
{
Number = 1
}
});
}
}
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
.NETStandard 2.0
- Microsoft.CodeAnalysis.CSharp (>= 4.2.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
2.1.0 | 503 | 7/25/2022 |
2.0.10 | 484 | 7/23/2022 |
2.0.9 | 478 | 7/23/2022 |
2.0.8 | 469 | 7/23/2022 |
2.0.7 | 476 | 7/23/2022 |
2.0.6 | 465 | 7/22/2022 |
2.0.5 | 455 | 7/22/2022 |
2.0.4 | 468 | 7/22/2022 |
2.0.3 | 517 | 4/11/2022 |
2.0.2 | 488 | 4/11/2022 |
2.0.1 | 502 | 4/7/2022 |
2.0.0 | 483 | 4/7/2022 |
1.7.2 | 488 | 4/4/2022 |
1.7.1 | 498 | 4/4/2022 |
1.7.0 | 470 | 4/4/2022 |
1.6.3 | 493 | 4/3/2022 |
1.6.2 | 501 | 4/3/2022 |
1.6.1 | 490 | 4/3/2022 |
1.6.0 | 486 | 4/3/2022 |