@@ -18,6 +18,7 @@ namespace JT808.DotNetty.Dtos | |||||
public const int Ok = 200; | public const int Ok = 200; | ||||
public const int Empty = 201; | public const int Empty = 201; | ||||
public const int NotFound = 404; | public const int NotFound = 404; | ||||
public const int Fail = 400; | |||||
public const int Error = 500; | public const int Error = 500; | ||||
} | } | ||||
} | } |
@@ -24,15 +24,24 @@ namespace JT808.DotNetty.Internal | |||||
var session = jT808SessionManager.GetSessionByTerminalPhoneNo(terminalPhoneNo); | var session = jT808SessionManager.GetSessionByTerminalPhoneNo(terminalPhoneNo); | ||||
if (session != null) | if (session != null) | ||||
{ | { | ||||
session.Channel.WriteAndFlushAsync(Unpooled.WrappedBuffer(data)); | |||||
resultDto.Code = JT808ResultCode.Ok; | |||||
resultDto.Data = true; | |||||
if (session.Channel.Open) | |||||
{ | |||||
session.Channel.WriteAndFlushAsync(Unpooled.WrappedBuffer(data)); | |||||
resultDto.Code = JT808ResultCode.Ok; | |||||
resultDto.Data = true; | |||||
} | |||||
else | |||||
{ | |||||
resultDto.Code = JT808ResultCode.Ok; | |||||
resultDto.Data = false; | |||||
resultDto.Message = "offline"; | |||||
} | |||||
} | } | ||||
else | else | ||||
{ | { | ||||
resultDto.Code = JT808ResultCode.Ok; | resultDto.Code = JT808ResultCode.Ok; | ||||
resultDto.Data = false; | resultDto.Data = false; | ||||
resultDto.Message = "not session"; | |||||
resultDto.Message = "offline"; | |||||
} | } | ||||
} | } | ||||
catch (Exception ex) | catch (Exception ex) | ||||
@@ -121,7 +121,15 @@ namespace JT808.DotNetty | |||||
public void TryAddOrUpdateSession(JT808Session appSession) | public void TryAddOrUpdateSession(JT808Session appSession) | ||||
{ | { | ||||
SessionIdDict.TryAdd(appSession.SessionID, appSession); | SessionIdDict.TryAdd(appSession.SessionID, appSession); | ||||
TerminalPhoneNo_SessionId_Dict.TryAdd(appSession.TerminalPhoneNo, appSession.SessionID); | |||||
if(TerminalPhoneNo_SessionId_Dict.TryAdd(appSession.TerminalPhoneNo, appSession.SessionID)) | |||||
{ | |||||
//使用场景: | |||||
//部标的超长待机设备,不会像正常的设备一样一直连着,可能10几分钟连上了,然后发完就关闭连接, | |||||
//这时候想下发数据需要知道设备什么时候上线,在这边做通知最好不过了。 | |||||
//todo: 有设备关联上来可以进行通知 | |||||
//todo: 使用Redis发布订阅 | |||||
} | |||||
} | } | ||||
public JT808Session RemoveSessionByID(string sessionID) | public JT808Session RemoveSessionByID(string sessionID) | ||||
@@ -137,6 +145,9 @@ namespace JT808.DotNetty | |||||
{ | { | ||||
TerminalPhoneNo_SessionId_Dict.TryRemove(key, out string sessionid); | TerminalPhoneNo_SessionId_Dict.TryRemove(key, out string sessionid); | ||||
} | } | ||||
//todo: 设备离线可以进行通知 | |||||
//todo: 使用Redis 发布订阅 | |||||
logger.LogInformation($">>>{sessionID}-{string.Join(",",removeKeys)} Session Remove."); | logger.LogInformation($">>>{sessionID}-{string.Join(",",removeKeys)} Session Remove."); | ||||
return session; | return session; | ||||
} | } | ||||