Networker
1.0.0
Pustaka jaringan TCP dan UDP yang mudah digunakan untuk .NET, dirancang agar fleksibel, terukur, dan CEPAT.
Manajer Paket NuGet
Install-Package Networker
Anda kemudian harus menginstal salah satu pemformat berikut
Install-Package Networker.Extensions.ZeroFormatter
Install-Package Networker.Extensions.MessagePack
Install-Package Networker.Extensions.ProtoBufNet
Install-Package Networker.Extensions.Json
Mulailah dengan tutorial ini yang ditulis oleh pengembang perpustakaan Mark Eastwood
Membuat server itu mudah..
var server = new ServerBuilder ( )
. UseTcp ( 1000 )
. UseUdp ( 5000 )
. RegisterPacketHandlerModule < DefaultPacketHandlerModule > ( )
. RegisterPacketHandlerModule < ExamplePacketHandlerModule > ( )
. UseZeroFormatter ( )
. ConfigureLogging ( loggingBuilder =>
{
loggingBuilder . AddConsole ( ) ;
loggingBuilder . SetMinimumLevel (
LogLevel . Debug ) ;
} )
. Build ( ) ;
server . Start ( ) ;
Anda dapat menangani paket dengan mudah menggunakan injeksi ketergantungan, logging, dan deserialisasi bawaan.
public class ChatPacketHandler : PacketHandlerBase < ChatPacket >
{
private readonly ILogger < ChatPacketHandler > _logger ;
public ChatPacketHandler ( ILogger < ChatPacketHandler > logger )
{
_logger = logger ;
}
public override async Task Process ( ChatPacket packet , IPacketContext packetContext )
{
_logger . LogDebug ( "I received the chat message: " + packet . Message ) ;
packetContext . Sender . Send ( new ChatPacket
{
Message = "Hey, I got your message!"
} ) ;
}
}