因为在初始化Hanlder的时候没有new Handler
ServerHandler serverHandler = new ServerHandler();
serverHandler.ReceivedData += ServerHandler_ReceivedData;
var workerGroup = new MultithreadEventLoopGroup();
bossGroup = new MultithreadEventLoopGroup(1);
bootstrap = new ServerBootstrap();
bootstrap
.Group(bossGroup, workerGroup)
.Channel<TcpServerSocketChannel>()
.ChildHandler(new ActionChannelInitializer<ISocketChannel>(channel =>
{
IChannelPipeline pipeline = channel.Pipeline;
pipeline.AddLast("TcpServerHandler", serverHandler);
}));
解决办法在Handler中重写IsSharable,并返回true
public class ServerHandler : ChannelHandlerAdapter
{
/// <summary>
/// 标记为Sharable
/// </summary>
public override bool IsSharable => true;
}
正常了