first commit
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
using DotNetty.Buffers;
|
||||
using DotNetty.Codecs;
|
||||
using DotNetty.Transport.Channels;
|
||||
using JSMachine.WMS.Infrastructure.Helper;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace JSMachine.WMS.Netty.NettyAsServer.Codec
|
||||
{
|
||||
public class Decoder : ByteToMessageDecoder
|
||||
{
|
||||
protected override void Decode(IChannelHandlerContext context, IByteBuffer input, List<object> output)
|
||||
{
|
||||
if (input != null)
|
||||
{
|
||||
int length = input.ReadableBytes;
|
||||
byte[] bytes = new byte[length];
|
||||
input.ReadBytes(bytes);
|
||||
try
|
||||
{
|
||||
//IMessagePackage message = MessagePackageMange.Instance.BinaryDeserializeToObject(bytes);
|
||||
output.Add(null);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error($"解码远程地址:{context.Channel.RemoteAddress}----发送的数据异常");
|
||||
}
|
||||
|
||||
input.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
using DotNetty.Buffers;
|
||||
using DotNetty.Codecs;
|
||||
using DotNetty.Transport.Channels;
|
||||
using JSMachine.WMS.Infrastructure.Helper;
|
||||
using System;
|
||||
using System.Text;
|
||||
|
||||
namespace JSMachine.WMS.Netty.NettyAsServer.Codec
|
||||
{
|
||||
public class Encoder : MessageToByteEncoder<string>
|
||||
{
|
||||
protected override void Encode(IChannelHandlerContext context, string message, IByteBuffer output)
|
||||
{
|
||||
try
|
||||
{
|
||||
byte[] body = Encoding.UTF8.GetBytes(message);
|
||||
byte[] tail = Encoding.UTF8.GetBytes("\r");
|
||||
|
||||
output.WriteBytes(body);
|
||||
output.WriteBytes(tail);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error($"TCP编码异常,异常信息 {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user