From dbea53aa75bfaa902436eda391ff0913ceff090d Mon Sep 17 00:00:00 2001 From: zhou-hao Date: Mon, 23 Mar 2020 14:33:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96tcp=20keepalive?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../network/tcp/device/TcpServerDeviceGateway.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/jetlinks-components/network-component/tcp-component/src/main/java/org/jetlinks/community/network/tcp/device/TcpServerDeviceGateway.java b/jetlinks-components/network-component/tcp-component/src/main/java/org/jetlinks/community/network/tcp/device/TcpServerDeviceGateway.java index b18ff9d9..1d12997c 100644 --- a/jetlinks-components/network-component/tcp-component/src/main/java/org/jetlinks/community/network/tcp/device/TcpServerDeviceGateway.java +++ b/jetlinks-components/network-component/tcp-component/src/main/java/org/jetlinks/community/network/tcp/device/TcpServerDeviceGateway.java @@ -177,12 +177,12 @@ class TcpServerDeviceGateway implements DeviceGateway, MonitorSupportDeviceGatew ); })) .flatMap(device -> { + DeviceSession fSession = sessionRef.get() == null ? + sessionManager.getSession(device.getDeviceId()) : + sessionRef.get(); + //处理设备上线消息 if (message instanceof DeviceOnlineMessage) { - DeviceSession fSession = sessionRef.get() == null ? - sessionManager.getSession(device.getDeviceId()) : - sessionRef.get(); - if (fSession == null) { fSession = new TcpDeviceSession(client.getId(), device, client, getTransport()) { @Override @@ -199,11 +199,15 @@ class TcpServerDeviceGateway implements DeviceGateway, MonitorSupportDeviceGatew sessionRef.set(fSession); sessionManager.register(fSession); } + fSession.keepAlive(); if (keepaliveTimeout.get() != null) { fSession.setKeepAliveTimeout(keepaliveTimeout.get()); } return Mono.empty(); } + if (fSession != null) { + fSession.keepAlive(); + } //设备下线 if (message instanceof DeviceOfflineMessage) { sessionManager.unregister(device.getDeviceId());