mirror of
https://github.com/Azure/DotNetty.git
synced 2026-10-29 12:42:40 +08:00
Motivation: If users want to change the ByteBuffer of the string, it is complicated. Modifications: Implement ToString methods in IByteBuffer and derived classes. Result: Users can easily use to change IByteBuffer to the string.
34 lines
1.0 KiB
C#
34 lines
1.0 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 Echo.Server
|
|
{
|
|
using System;
|
|
using System.Text;
|
|
using DotNetty.Buffers;
|
|
using DotNetty.Transport.Channels;
|
|
|
|
public class EchoServerHandler : ChannelHandlerAdapter
|
|
{
|
|
public override void ChannelRead(IChannelHandlerContext context, object message)
|
|
{
|
|
IByteBuffer buffer = message as IByteBuffer;
|
|
if (buffer != null)
|
|
{
|
|
Console.WriteLine("Received from client: " + buffer.ToString(Encoding.UTF8));
|
|
}
|
|
context.WriteAsync(message);
|
|
}
|
|
|
|
public override void ChannelReadComplete(IChannelHandlerContext context)
|
|
{
|
|
context.Flush();
|
|
}
|
|
|
|
public override void ExceptionCaught(IChannelHandlerContext context, Exception exception)
|
|
{
|
|
Console.WriteLine("Exception: " + exception);
|
|
context.CloseAsync();
|
|
}
|
|
}
|
|
}
|