mirror of
https://github.com/Azure/DotNetty.git
synced 2026-10-18 22:30:36 +08:00
4f28a55b48
Motivation .NET Core tooling allows building for both .NET Framework and .NET Standard while easing pains of running tests and packaging. Modifications - csproj -> xproj + project.json - support for .NET Standard 1.3 - build script is now based on CAKE - using dotnet CLI for building, testing, packing - strong name by default (snk included) Result DotNetty works on .NET Core and any other platform supporting .NET Standard 1.3+.
52 lines
1.6 KiB
C#
52 lines
1.6 KiB
C#
// Copyright (c) Microsoft. All rights reserved.
|
|
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
|
|
|
namespace Discard.Client
|
|
{
|
|
using System;
|
|
using DotNetty.Buffers;
|
|
using DotNetty.Transport.Channels;
|
|
using Examples.Common;
|
|
|
|
public class DiscardClientHandler : SimpleChannelInboundHandler<object>
|
|
{
|
|
IChannelHandlerContext ctx;
|
|
byte[] array;
|
|
|
|
public override void ChannelActive(IChannelHandlerContext ctx)
|
|
{
|
|
this.array = new byte[ClientSettings.Size];
|
|
this.ctx = ctx;
|
|
|
|
// Send the initial messages.
|
|
this.GenerateTraffic();
|
|
}
|
|
|
|
protected override void ChannelRead0(IChannelHandlerContext context, object message)
|
|
{
|
|
// Server is supposed to send nothing, but if it sends something, discard it.
|
|
}
|
|
|
|
public override void ExceptionCaught(IChannelHandlerContext ctx, Exception e)
|
|
{
|
|
Console.WriteLine("{0}", e.ToString());
|
|
this.ctx.CloseAsync();
|
|
}
|
|
|
|
async void GenerateTraffic()
|
|
{
|
|
try
|
|
{
|
|
IByteBuffer buffer = Unpooled.WrappedBuffer(this.array);
|
|
// Flush the outbound buffer to the socket.
|
|
// Once flushed, generate the same amount of traffic again.
|
|
await this.ctx.WriteAndFlushAsync(buffer);
|
|
this.GenerateTraffic();
|
|
}
|
|
catch
|
|
{
|
|
await this.ctx.CloseAsync();
|
|
}
|
|
}
|
|
}
|
|
} |