public JT808ResultDto <bool> Send(string terminalPhoneNo, byte[] data) { JT808ResultDto <bool> resultDto = new JT808ResultDto <bool>(); try { var session = jT808SessionManager.GetSession(terminalPhoneNo); if (session != null) { //判断转发数据是下发不了消息的 if (jT808SessionManager.GetAll().Count(c => c.Channel.Id == session.Channel.Id) > 1) { resultDto.Code = JT808ResultCode.Ok; resultDto.Data = false; resultDto.Message = "not support transmit data send."; } else { jT808TcpTrafficService.SendSize(data.Length); session.Channel.WriteAndFlushAsync(Unpooled.WrappedBuffer(data)); resultDto.Code = JT808ResultCode.Ok; resultDto.Data = true; } } else { resultDto.Code = JT808ResultCode.Ok; resultDto.Data = false; resultDto.Message = "offline"; } } catch (Exception ex) { resultDto.Data = false; resultDto.Code = JT808ResultCode.Error; resultDto.Message = Newtonsoft.Json.JsonConvert.SerializeObject(ex); } return(resultDto); }
public JT808ResultDto <List <JT808TcpSessionInfoDto> > GetAll() { JT808ResultDto <List <JT808TcpSessionInfoDto> > resultDto = new JT808ResultDto <List <JT808TcpSessionInfoDto> >(); try { resultDto.Data = jT808SessionManager.GetAll().Select(s => new JT808TcpSessionInfoDto { LastActiveTime = s.LastActiveTime, StartTime = s.StartTime, TerminalPhoneNo = s.TerminalPhoneNo, RemoteAddressIP = s.Channel.RemoteAddress.ToString(), }).ToList(); resultDto.Code = JT808ResultCode.Ok; } catch (Exception ex) { resultDto.Data = null; resultDto.Code = JT808ResultCode.Error; resultDto.Message = Newtonsoft.Json.JsonConvert.SerializeObject(ex); } return(resultDto); }