DotNetty.Wraper 0.7.31

dotnet add package DotNetty.Wraper --version 0.7.31                
NuGet\Install-Package DotNetty.Wraper -Version 0.7.31                
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="DotNetty.Wraper" Version="0.7.31" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DotNetty.Wraper --version 0.7.31                
#r "nuget: DotNetty.Wraper, 0.7.31"                
#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.
// Install DotNetty.Wraper as a Cake Addin
#addin nuget:?package=DotNetty.Wraper&version=0.7.31

// Install DotNetty.Wraper as a Cake Tool
#tool nuget:?package=DotNetty.Wraper&version=0.7.31                

DotNetty.Wraper

Description

将微软的Azure/DotNetty 代码重新整理,支持netstandard2.0;net472;net45,可以直接在各个 版本中使用。 并将多个类库合并成到一个项目中,加了些封装类,开箱即用。

封装类的示例:

Client

using DotNetty.Wraper;
using Examples.Common;
using Microsoft.Extensions.Logging;
using System;
using System.Text;
using System.Threading.Tasks;

namespace TcpSocket.Client
{
    class Program
    {
        static async Task Main(string[] args)
        {
            ILogger _logger = new CNative.Logging.ConfigLogger();
            var option = new ClientOption();
            option.SeverIp = Examples.Common.ClientSettings.Host.ToString();
            option.Port = Examples.Common.ClientSettings.Port;
            option.UseLibuv = Examples.Common.ClientSettings.UseLibuv;
            if (Examples.Common.ServerSettings.IsSsl)
            {
                option.Certificate = System.IO.Path.Combine(ExampleHelper.ProcessDirectory, "dotnetty.com.pfx");
                option.CertificatePassword = "password";
            }
            var theClientBuild = SocketBuilderFactory.GetTcpSocketClientBuilder(option)
                .OnChannelRegistered((client, channel) =>
                {
                    _logger.LogDebug("OnChannelRegistered: " + channel.Id);
                })
                .OnChannelRegistered((client, channel) =>
                {
                    _logger.LogDebug("OnChannelRegistered: " + channel.Id);
                })
                .OnClientStarted(client =>
                {
                    _logger.LogInformation($"客户端启动");
                    client.Send("Hello world" + DateTime.Now);
                })
                .OnClientClose(client =>
                {
                    _logger.LogInformation($"客户端关闭");
                })
                .OnException(ex =>
                {
                    _logger.LogError($"异常:{ex.Message}");
                })
                .OnRecieve((client, bytes) =>
                {
                    _logger.LogInformation($"客户端:收到数据:{Encoding.UTF8.GetString(bytes)}");
                    client.Send("Hello world " + DateTime.Now);
                })
                .OnSend((client, bytes) =>
                {
                    _logger.LogInformation($"客户端:发送数据:{Encoding.UTF8.GetString(bytes)}");
                });

            var theClient = await theClientBuild .BuildAsync((pipeline) =>
            {
                pipeline.AddLast("framing-enc", new DotNetty.Codecs.LengthFieldPrepender(2));
                pipeline.AddLast("framing-dec", new DotNetty.Codecs.LengthFieldBasedFrameDecoder(ushort.MaxValue, 0, 2, 0, 2));
            });
            Console.ReadLine();

            theClient?.Close();
        }
    }
}

Server


using System;
using System.Text;
using System.Threading.Tasks;

using DotNetty.Wraper;
using Examples.Common;
using Microsoft.Extensions.Logging;

namespace TcpSocket.Server
{
    class Program
    {
        static async Task Main(string[] args)
        {
            ILogger _logger = new CNative.Logging.ConfigLogger();

            var option = new ServerOption();
            option.Port = Examples.Common.ServerSettings.Port;
            option.UseLibuv = Examples.Common.ServerSettings.UseLibuv;
            if (Examples.Common.ServerSettings.IsSsl)
            {
                option.Certificate = System.IO.Path.Combine(ExampleHelper.ProcessDirectory, "dotnetty.com.pfx");
                option.CertificatePassword = "password";
            }
            var theServerBuild = SocketBuilderFactory.GetTcpSocketServerBuilder(option)
             .OnConnectionClose((server, connection) =>
             {
                 _logger.LogInformation($"连接关闭,连接名[{connection.ConnectionName}],当前连接数:{server.GetConnectionCount()}");
             })
             .OnException(ex =>
             {
                 _logger.LogError($"服务端异常:{ex.Message}");
             })
             .OnChannelRegistered((server, channel) =>
             {
                 _logger.LogDebug("ChannelUnregistered: " + channel.Id);
             })
             .OnChannelRegistered((server, channel) =>
             {
                 _logger.LogDebug("ChannelRegistered: " + channel.Id);
             })
             .OnNewConnection((server, connection) =>
             {
                 connection.ConnectionName = $"名字{connection.ConnectionId}";
                 _logger.LogInformation($"新的连接[{connection.ClientAddress.Address.MapToIPv4().ToString()}]:{connection.ConnectionName},当前连接数:{server.GetConnectionCount()}");
             })
             .OnRecieve((server, connection, bytes) =>
             {
                 _logger.LogInformation($"服务端:数据{Encoding.UTF8.GetString(bytes)}");
                 connection.Send(bytes);
             })
             .OnSend((server, connection, bytes) =>
             {
                 _logger.LogInformation($"向连接名[{connection.ConnectionName}]发送数据:{Encoding.UTF8.GetString(bytes)}");
             })
             .OnServerStarted(server =>
             {
                 _logger.LogInformation($"服务启动");
             });
            var theServer = await theServerBuild.BuildAsync((pipeline) =>
            {
                pipeline.AddLast("framing-enc", new DotNetty.Codecs.LengthFieldPrepender(2));
                pipeline.AddLast("framing-dec", new DotNetty.Codecs.LengthFieldBasedFrameDecoder(ushort.MaxValue, 0, 2, 0, 2));
            });

            Console.ReadLine();

            theServer?.Close();
        }
    }
}

DotNetty Project

Join the chat at https://gitter.im/Azure/DotNetty Available on NuGet https://www.nuget.org/packages?q=DotNetty.Wraper AppVeyor

DotNetty.Wraper is a port of Netty, asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients.

Use

  • Official releases are on NuGet.
  • Nightly builds are available on MyGet.

Contribute

We gladly accept community contributions.

Product 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. 
.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 net45 is compatible.  net451 was computed.  net452 was computed.  net46 was computed.  net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 is compatible.  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.

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
0.7.31 952 5/19/2022
0.7.3 875 5/15/2022
0.7.2 850 5/15/2022