|
|
@ -32,9 +32,12 @@ public class TcpServer<TH, TD, TE> : IDisposable where TH : IChannelHandler
|
|
|
|
private int _port = 9000;
|
|
|
|
private int _port = 9000;
|
|
|
|
|
|
|
|
|
|
|
|
public LogLevel? LogLevel { get; set; }
|
|
|
|
public LogLevel? LogLevel { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Action? ChannelInActiveAction { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
public TcpServer()
|
|
|
|
public TcpServer()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
if (LogLevel != null)
|
|
|
|
if (LogLevel != null)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
InternalLoggerFactory.DefaultFactory.AddProvider(new Log4NetProvider());
|
|
|
|
InternalLoggerFactory.DefaultFactory.AddProvider(new Log4NetProvider());
|
|
|
@ -49,12 +52,12 @@ public class TcpServer<TH, TD, TE> : IDisposable where TH : IChannelHandler
|
|
|
|
.Handler(new LoggingHandler())
|
|
|
|
.Handler(new LoggingHandler())
|
|
|
|
.ChildHandler(new ActionChannelInitializer<ISocketChannel>(channel =>
|
|
|
|
.ChildHandler(new ActionChannelInitializer<ISocketChannel>(channel =>
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var serverListenerHandler = new ServerListenerHandler<TH, TD, TE>();
|
|
|
|
var serverListenerHandler = new ServerListenerHandler<TH, TD, TE>
|
|
|
|
var pipeline = channel.Pipeline;
|
|
|
|
|
|
|
|
if (LogLevel != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
pipeline.AddLast(new LoggingHandler(LogLevel.Value));
|
|
|
|
ChannelInActiveAction = ChannelInActiveAction
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var pipeline = channel.Pipeline;
|
|
|
|
|
|
|
|
pipeline.AddLast(new LoggingHandler());
|
|
|
|
pipeline.AddLast(serverListenerHandler);
|
|
|
|
pipeline.AddLast(serverListenerHandler);
|
|
|
|
pipeline.AddLast(new IdleStateHandler(0, 0, 180)); //检测空闲连接
|
|
|
|
pipeline.AddLast(new IdleStateHandler(0, 0, 180)); //检测空闲连接
|
|
|
|
//业务handler ,这里是实际处理业务的Handler
|
|
|
|
//业务handler ,这里是实际处理业务的Handler
|
|
|
|