public JT809SubordinateClient(
     IServiceProvider provider,
     ILoggerFactory loggerFactory,
     IJT809SubordinateLinkNotifyService subordinateLinkNotifyService,
     IJT809VerifyCodeGenerator verifyCodeGenerator)
 {
     this.serviceProvider     = provider;
     this.loggerFactory       = loggerFactory;
     this.verifyCodeGenerator = verifyCodeGenerator;
     this.logger = loggerFactory.CreateLogger <JT809SubordinateClient>();
     this.subordinateLinkNotifyService = subordinateLinkNotifyService;
     group     = new MultithreadEventLoopGroup();
     bootstrap = new Bootstrap();
     bootstrap.Group(group)
     .Channel <TcpSocketChannel>()
     .Option(ChannelOption.TcpNodelay, true)
     .Handler(new ActionChannelInitializer <ISocketChannel>(channel =>
     {
         IChannelPipeline pipeline = channel.Pipeline;
         //下级平台1分钟发送心跳
         //上级平台是3分钟没有发送就断开连接
         using (var scope = serviceProvider.CreateScope())
         {
             pipeline.AddLast("jt809SubClientBuffer", new DelimiterBasedFrameDecoder(int.MaxValue,
                                                                                     Unpooled.CopiedBuffer(new byte[] { JT809Package.BEGINFLAG }),
                                                                                     Unpooled.CopiedBuffer(new byte[] { JT809Package.ENDFLAG })));
             pipeline.AddLast("jt809SubClientSystemIdleState", new IdleStateHandler(180, 60, 200));
             pipeline.AddLast("jt809SubClientEncode", scope.ServiceProvider.GetRequiredService <JT809Encoder>());
             pipeline.AddLast("jt809SubClientDecode", scope.ServiceProvider.GetRequiredService <JT809Decoder>());
             pipeline.AddLast("jt809SubClientConnection", scope.ServiceProvider.GetRequiredService <JT809SubordinateClientConnectionHandler>());
             pipeline.AddLast("jt809SubClientServer", scope.ServiceProvider.GetRequiredService <JT809SubordinateClientHandler>());
         }
     }));
 }
예제 #2
0
 public JT809SubordinateClientConnectionHandler(
     IJT809SubordinateLinkNotifyService jT809SubordinateLinkNotifyService,
     JT809SubordinateClient jT809SubordinateClient,
     ILoggerFactory loggerFactory)
 {
     logger = loggerFactory.CreateLogger <JT809SubordinateClientConnectionHandler>();
     JT809SubordinateLinkNotifyService = jT809SubordinateLinkNotifyService;
     subordinateClient = jT809SubordinateClient;
 }
 public JT809SubordinateClientConnectionHandler(
     IJT809Config jT809Config,
     IJT809SubordinateLinkNotifyService jT809SubordinateLinkNotifyService,
     JT809SubordinateClient jT809SubordinateClient,
     ILoggerFactory loggerFactory)
 {
     JT809Serializer = jT809Config.GetSerializer();
     logger          = loggerFactory.CreateLogger <JT809SubordinateClientConnectionHandler>();
     JT809SubordinateLinkNotifyService = jT809SubordinateLinkNotifyService;
     subordinateClient = jT809SubordinateClient;
 }