mirror of
https://github.com/Azure/DotNetty.git
synced 2026-10-19 06:31:20 +08:00
44885964bd
Motivation: Ported/Re-implemented DatagramChannel/UDP into DotNetty Modifications: - Added DatagramChannel/Config into transport project. - Added DatagramPacket/DefaultAddressedEnvelop/IAddressedEnvelop into transport project. - Added DatagramPacketEncoder/DatagramPacketDecoder into Codec project. - Extra: Ported QuoteOfTheMoment UDP example project. Result: DatagramChannel/UDP transport is supported by DotNetty.
38 lines
1.2 KiB
C#
38 lines
1.2 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 DotNetty.Codecs.Tests
|
|
{
|
|
using System.Net;
|
|
using System.Text;
|
|
using DotNetty.Buffers;
|
|
using DotNetty.Codecs;
|
|
using DotNetty.Transport.Channels.Embedded;
|
|
using DotNetty.Transport.Channels.Sockets;
|
|
using Xunit;
|
|
|
|
public class DatagramPacketDecoderTest
|
|
{
|
|
[Fact]
|
|
public void Decode()
|
|
{
|
|
var channel = new EmbeddedChannel(new DatagramPacketDecoder(new StringDecoder(Encoding.UTF8)));
|
|
var recipient = new IPEndPoint(IPAddress.Loopback, 10000);
|
|
var sender = new IPEndPoint(IPAddress.Loopback, 20000);
|
|
|
|
const string Content = "netty";
|
|
IByteBuffer data = Unpooled.WrappedBuffer(Encoding.UTF8.GetBytes(Content));
|
|
try
|
|
{
|
|
Assert.True(channel.WriteInbound(new DatagramPacket(data, sender, recipient)));
|
|
string content = channel.ReadInbound<string>();
|
|
Assert.Equal(Content, content);
|
|
}
|
|
finally
|
|
{
|
|
Assert.False(channel.Finish());
|
|
}
|
|
}
|
|
}
|
|
}
|