public void Test1()
        {
            // 作为源包转发服务端
            DispatcherEventLoopGroup bossGroup   = new DispatcherEventLoopGroup();
            WorkerEventLoopGroup     workerGroup = new WorkerEventLoopGroup(bossGroup, 1);
            ServerBootstrap          bootstrap   = new ServerBootstrap();

            bootstrap.Group(bossGroup, workerGroup);
            bootstrap.Channel <TcpServerChannel>();
            if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ||
                RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                bootstrap
                .Option(ChannelOption.SoReuseport, true)
                .ChildOption(ChannelOption.SoReuseaddr, true);
            }
            bootstrap
            .ChildHandler(new ActionChannelInitializer <IChannel>(channel =>
            {
                IChannelPipeline pipeline = channel.Pipeline;
                channel.Pipeline.AddLast("jt808Buffer", new DelimiterBasedFrameDecoder(int.MaxValue,
                                                                                       Unpooled.CopiedBuffer(new byte[] { JT808.Protocol.JT808Package.BeginFlag }),
                                                                                       Unpooled.CopiedBuffer(new byte[] { JT808.Protocol.JT808Package.EndFlag })));
                channel.Pipeline.AddLast("jt808Decode", new JT808ClientDecoder());
            }));
            bootstrap.BindAsync(6655);
            //作为设备上传
            byte[] bytes = "7E 02 00 00 26 12 34 56 78 90 12 00 7D 02 00 00 00 01 00 00 00 02 00 BA 7F 0E 07 E4 F1 1C 00 28 00 3C 00 00 18 10 15 10 10 10 01 04 00 00 00 64 02 02 00 7D 01 13 7E".ToHexBytes();
            SimpleTcpClient.WriteAsync(bytes);
            Thread.Sleep(10000);
            SimpleTcpClient.Down();
        }
        public void RemoveByChannelIdTest()
        {
            // 心跳会话包
            JT808Package jT808Package1 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("99");

            SimpleTcpClient.WriteAsync(JT808Serializer.Serialize(jT808Package1));

            var    result4  = httpClient.PostAsync($"{Url}/{sessionRoutePrefix}/RemoveByChannelId", new StringContent("99")).Result;
            string content4 = result4.Content.ReadAsStringAsync().Result;
            JT808ResultDto <bool> jt808Result4 = JsonConvert.DeserializeObject <JT808ResultDto <bool> >(content4);

            Assert.Equal(200, jt808Result4.Code);
            Assert.True(jt808Result4.Data);
        }
Пример #3
0
        public JT808SessionServiceTest()
        {
            SimpleTcpClient1 = new JT808SimpleTcpClient(endPoint);
            SimpleTcpClient2 = new JT808SimpleTcpClient(endPoint);
            SimpleTcpClient3 = new JT808SimpleTcpClient(endPoint);
            SimpleTcpClient4 = new JT808SimpleTcpClient(endPoint);
            SimpleTcpClient5 = new JT808SimpleTcpClient(endPoint);
            // 心跳会话包
            JT808Package jT808Package1 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789001");

            SimpleTcpClient1.WriteAsync(JT808Serializer.Serialize(jT808Package1));

            // 心跳会话包
            JT808Package jT808Package2 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789002");

            SimpleTcpClient2.WriteAsync(JT808Serializer.Serialize(jT808Package2));

            // 心跳会话包
            JT808Package jT808Package3 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789003");

            SimpleTcpClient3.WriteAsync(JT808Serializer.Serialize(jT808Package3));

            // 心跳会话包
            JT808Package jT808Package4 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789004");

            SimpleTcpClient4.WriteAsync(JT808Serializer.Serialize(jT808Package4));

            // 心跳会话包
            JT808Package jT808Package5 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789005");

            SimpleTcpClient5.WriteAsync(JT808Serializer.Serialize(jT808Package5));
            Thread.Sleep(1000);
        }
        public void Test2()
        {
            // 心跳会话包
            JT808Package jT808Package1 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789012");

            SimpleTcpClient.WriteAsync(JT808Serializer.Serialize(jT808Package1));

            // 文本信息包
            JT808Package jT808Package2 = JT808.Protocol.Enums.JT808MsgId.文本信息下发.Create("123456789012", new JT808_0x8300
            {
                TextFlag = 5,
                TextInfo = "smallchi 518"
            });
            var data = JT808Serializer.Serialize(jT808Package2);

            JT808UnificationSendRequestDto jT808UnificationSendRequestDto = new JT808UnificationSendRequestDto();

            jT808UnificationSendRequestDto.TerminalPhoneNo = "123456789012";
            jT808UnificationSendRequestDto.Data            = data;

            HttpClient httpClient = new HttpClient();
            // 调用内置的http服务接收文本信息下发
            var    result  = httpClient.PostAsync("http://127.0.0.1:828/jt808api/UnificationSend", new StringContent(JsonConvert.SerializeObject(jT808UnificationSendRequestDto))).Result;
            string content = result.Content.ReadAsStringAsync().Result;
            JT808ResultDto <bool> jt808Result = JsonConvert.DeserializeObject <JT808ResultDto <bool> >(content);

            Assert.Equal(200, jt808Result.Code);
            Assert.True(jt808Result.Data);
            SimpleTcpClient.Down();
        }
        public void Test2()
        {
            // 心跳会话包
            JT808Package jT808Package1 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789001");

            SimpleTcpClient.WriteAsync(JT808Serializer.Serialize(jT808Package1));

            // 心跳会话包
            JT808Package jT808Package2 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789002");

            SimpleTcpClient.WriteAsync(JT808Serializer.Serialize(jT808Package2));

            // 心跳会话包
            JT808Package jT808Package3 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789003");

            SimpleTcpClient.WriteAsync(JT808Serializer.Serialize(jT808Package3));

            // 心跳会话包
            JT808Package jT808Package4 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789004");

            SimpleTcpClient.WriteAsync(JT808Serializer.Serialize(jT808Package4));

            // 心跳会话包
            JT808Package jT808Package5 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789005");

            SimpleTcpClient.WriteAsync(JT808Serializer.Serialize(jT808Package5));

            // 异步的需要延时下
            Thread.Sleep(1000);

            HttpClient httpClient = new HttpClient();
            // 调用内置的http服务接收文本信息下发
            var    result  = httpClient.GetAsync("http://127.0.0.1:828/jt808api/GetAtomicCounter").Result;
            string content = result.Content.ReadAsStringAsync().Result;
            JT808ResultDto <JT808AtomicCounterDto> jt808Result = JsonConvert.DeserializeObject <JT808ResultDto <JT808AtomicCounterDto> >(content);

            Assert.Equal(200, jt808Result.Code);
            Assert.Equal(5, jt808Result.Data.MsgSuccessCount);
            Assert.Equal(0, jt808Result.Data.MsgFailCount);
            SimpleTcpClient.Down();
        }
 public JT808WebAPIServiceTest()
 {
     SimpleTcpClient = new JT808SimpleTcpClient(endPoint);
     httpClient      = new HttpClient();
     for (var i = 1; i <= length; i++)
     {
         // 心跳会话包
         JT808Package jT808Package1 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create($"{i.ToString()}");
         SimpleTcpClient.WriteAsync(JT808Serializer.Serialize(jT808Package1));
     }
     Thread.Sleep(300);
 }
        /// <summary>
        /// 需要使用 SocketTool 创建tcp服务器
        /// </summary>
        public JT808SourcePackageChannelServiceTest()
        {
            SimpleTcpClient = new JT808SimpleTcpClient(endPoint, new IPEndPoint(IPAddress.Parse("127.0.0.1"), 6555));
            //作为设备5秒上传
            Task.Run(() =>
            {
                Random random = new Random();
                while (true)
                {
                    JT808Package jT808Package = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("12345678900" + random.Next(0, 2).ToString());
                    SimpleTcpClient.WriteAsync(JT808Serializer.Serialize(jT808Package));
                    Thread.Sleep(1000);
                }
            });

            // 作为源包转发服务端
            DispatcherEventLoopGroup bossGroup   = new DispatcherEventLoopGroup();
            WorkerEventLoopGroup     workerGroup = new WorkerEventLoopGroup(bossGroup, 1);
            ServerBootstrap          bootstrap   = new ServerBootstrap();

            bootstrap.Group(bossGroup, workerGroup);
            bootstrap.Channel <TcpServerChannel>();
            bootstrap
            .ChildHandler(new ActionChannelInitializer <IChannel>(channel =>
            {
                IChannelPipeline pipeline = channel.Pipeline;
                channel.Pipeline.AddLast("jt808Buffer", new DelimiterBasedFrameDecoder(int.MaxValue,
                                                                                       Unpooled.CopiedBuffer(new byte[] { JT808.Protocol.JT808Package.BeginFlag }),
                                                                                       Unpooled.CopiedBuffer(new byte[] { JT808.Protocol.JT808Package.EndFlag })));
                channel.Pipeline.AddLast("jt808Decode", new JT808ClientDecoder());
            }));
            bootstrap.BindAsync(6655);

            DispatcherEventLoopGroup bossGroup1   = new DispatcherEventLoopGroup();
            WorkerEventLoopGroup     workerGroup1 = new WorkerEventLoopGroup(bossGroup1, 1);
            ServerBootstrap          bootstrap1   = new ServerBootstrap();

            bootstrap1.Group(bossGroup1, workerGroup1);
            bootstrap1.Channel <TcpServerChannel>();
            bootstrap1
            .ChildHandler(new ActionChannelInitializer <IChannel>(channel =>
            {
                IChannelPipeline pipeline = channel.Pipeline;
                channel.Pipeline.AddLast("jt808Buffer", new DelimiterBasedFrameDecoder(int.MaxValue,
                                                                                       Unpooled.CopiedBuffer(new byte[] { JT808.Protocol.JT808Package.BeginFlag }),
                                                                                       Unpooled.CopiedBuffer(new byte[] { JT808.Protocol.JT808Package.EndFlag })));
                channel.Pipeline.AddLast("jt808Decode", new JT808ClientDecoder());
            }));
            bootstrap1.BindAsync(6656);
        }
        public void Test1()
        {
            IJT808SessionService jT808SessionServiceDefaultImpl = ServiceProvider.GetService <IJT808SessionService>();
            JT808SimpleTcpClient SimpleTcpClient1 = new JT808SimpleTcpClient(endPoint);
            JT808SimpleTcpClient SimpleTcpClient2 = new JT808SimpleTcpClient(endPoint);
            JT808SimpleTcpClient SimpleTcpClient3 = new JT808SimpleTcpClient(endPoint);
            JT808SimpleTcpClient SimpleTcpClient4 = new JT808SimpleTcpClient(endPoint);
            JT808SimpleTcpClient SimpleTcpClient5 = new JT808SimpleTcpClient(endPoint);
            // 心跳会话包
            JT808Package jT808Package1 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789001");

            SimpleTcpClient1.WriteAsync(JT808Serializer.Serialize(jT808Package1));

            // 心跳会话包
            JT808Package jT808Package2 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789002");

            SimpleTcpClient2.WriteAsync(JT808Serializer.Serialize(jT808Package2));

            // 心跳会话包
            JT808Package jT808Package3 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789003");

            SimpleTcpClient3.WriteAsync(JT808Serializer.Serialize(jT808Package3));

            // 心跳会话包
            JT808Package jT808Package4 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789004");

            SimpleTcpClient4.WriteAsync(JT808Serializer.Serialize(jT808Package4));

            // 心跳会话包
            JT808Package jT808Package5 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789005");

            SimpleTcpClient5.WriteAsync(JT808Serializer.Serialize(jT808Package5));
            Thread.Sleep(1000);
            var result = jT808SessionServiceDefaultImpl.GetAll();

            var info5 = result.Data.FirstOrDefault(f => f.TerminalPhoneNo == "123456789005");

            var remove5 = jT808SessionServiceDefaultImpl.RemoveByChannelId(info5.ChannelId);

            var result1 = jT808SessionServiceDefaultImpl.GetAll();

            Thread.Sleep(10000);

            SimpleTcpClient1.Down();
            SimpleTcpClient2.Down();
            SimpleTcpClient3.Down();
            SimpleTcpClient4.Down();
            SimpleTcpClient5.Down();
        }
Пример #9
0
        public TestBase()
        {
            SimpleTcpClient1 = new JT808SimpleTcpClient(endPoint);
            SimpleTcpClient2 = new JT808SimpleTcpClient(endPoint);
            SimpleTcpClient3 = new JT808SimpleTcpClient(endPoint);
            SimpleTcpClient4 = new JT808SimpleTcpClient(endPoint);
            SimpleTcpClient5 = new JT808SimpleTcpClient(endPoint);
            // 心跳会话包
            JT808Package jT808Package1 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789001");

            SimpleTcpClient1.WriteAsync(JT808Serializer.Serialize(jT808Package1));

            // 心跳会话包
            JT808Package jT808Package2 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789002");

            SimpleTcpClient2.WriteAsync(JT808Serializer.Serialize(jT808Package2));

            // 心跳会话包
            JT808Package jT808Package3 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789003");

            SimpleTcpClient3.WriteAsync(JT808Serializer.Serialize(jT808Package3));

            // 心跳会话包
            JT808Package jT808Package4 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789004");

            SimpleTcpClient4.WriteAsync(JT808Serializer.Serialize(jT808Package4));

            // 心跳会话包
            JT808Package jT808Package5 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789005");

            SimpleTcpClient5.WriteAsync(JT808Serializer.Serialize(jT808Package5));

            SimpleUdpClient1 = new JT808SimpleUdpClient(endPoint1);
            SimpleUdpClient2 = new JT808SimpleUdpClient(endPoint1);
            SimpleUdpClient3 = new JT808SimpleUdpClient(endPoint1);
            SimpleUdpClient4 = new JT808SimpleUdpClient(endPoint1);
            SimpleUdpClient5 = new JT808SimpleUdpClient(endPoint1);
            // 心跳会话包
            JT808Package jT808Package12 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789011");

            SimpleUdpClient1.WriteAsync(JT808Serializer.Serialize(jT808Package12));
            Thread.Sleep(300);
            // 心跳会话包
            JT808Package jT808Package23 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789012");

            SimpleUdpClient2.WriteAsync(JT808Serializer.Serialize(jT808Package23));
            Thread.Sleep(300);
            // 心跳会话包
            JT808Package jT808Package34 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789013");

            SimpleUdpClient3.WriteAsync(JT808Serializer.Serialize(jT808Package34));
            Thread.Sleep(300);
            // 心跳会话包
            JT808Package jT808Package45 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789014");

            SimpleUdpClient4.WriteAsync(JT808Serializer.Serialize(jT808Package45));
            Thread.Sleep(300);
            // 心跳会话包
            JT808Package jT808Package56 = JT808.Protocol.Enums.JT808MsgId.终端心跳.Create("123456789015");

            SimpleUdpClient5.WriteAsync(JT808Serializer.Serialize(jT808Package56));

            Thread.Sleep(300);
        }