• This repository has been archived on 25/Feb/2020
  • Stars
    star
    477
  • Rank 92,112 (Top 2 %)
  • Language
    C#
  • License
    MIT License
  • Created over 7 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A simple to use TCP and UDP networking library for .NET. Compatible with Unity.

Build status NuGet

Networker

A simple to use TCP and UDP networking library for .NET, designed to be flexible, scalable and FAST.

Supported Frameworks

  • .NET Standard 2.0
  • .NET Framework 4.7+ for Unity

Features

Installation

NuGet Package Manager

Install-Package Networker

You must then install one of the following formatters

ZeroFormatter

Install-Package Networker.Extensions.ZeroFormatter

MessagePack

Install-Package Networker.Extensions.MessagePack

Protobuf-net

Install-Package Networker.Extensions.ProtoBufNet

JSON (Utf8Json)

Install-Package Networker.Extensions.Json

Tutorial - Creating a Basic Unity Multiplayer Game with Networker

Get started with this tutorial written by the library developer Mark Eastwood

Example

Creating a server is easy..

var server = new ServerBuilder()
                .UseTcp(1000)
                .UseUdp(5000)
                .RegisterPacketHandlerModule<DefaultPacketHandlerModule>()
                .RegisterPacketHandlerModule<ExamplePacketHandlerModule>()
                .UseZeroFormatter()
                .ConfigureLogging(loggingBuilder =>
                                    {
                                        loggingBuilder.AddConsole();
                                        loggingBuilder.SetMinimumLevel(
                                            LogLevel.Debug);
                                    })
                .Build();

server.Start();

You can handle a packet easily using dependency injection, logging and built-in deserialisation.

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!"
		});
	}
}