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 Dispose() { SimpleTcpClient1.Down(); SimpleTcpClient2.Down(); SimpleTcpClient3.Down(); SimpleTcpClient4.Down(); SimpleTcpClient5.Down(); }
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 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(); }
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 override void Dispose() { base.Dispose(); SimpleTcpClient.Down(); }