|
@@ -2,7 +2,7 @@ package com.gzlh.background.client;
|
|
|
|
|
|
import com.gzlh.background.properties.BackgroundPropertiesConfig;
|
|
|
import com.gzlh.led.properties.LedPropertiesConfig;
|
|
|
-import com.gzlh.socket.TestClientHandler;
|
|
|
+import com.gzlh.utils.DeviceCache;
|
|
|
import io.netty.bootstrap.Bootstrap;
|
|
|
import io.netty.channel.*;
|
|
|
import io.netty.channel.nio.NioEventLoopGroup;
|
|
@@ -13,6 +13,7 @@ import io.netty.handler.codec.string.StringEncoder;
|
|
|
import io.netty.handler.timeout.IdleStateHandler;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
@@ -33,6 +34,7 @@ public class BackgroundClientNetty {
|
|
|
|
|
|
@Bean("backgroundClient")
|
|
|
public Bootstrap bootstrap() {
|
|
|
+
|
|
|
EventLoopGroup group = new NioEventLoopGroup();
|
|
|
bootstrap = new Bootstrap();
|
|
|
return bootstrap.group(group)
|
|
@@ -44,7 +46,7 @@ public class BackgroundClientNetty {
|
|
|
socketChannel.pipeline()
|
|
|
.addLast("decoder", new StringDecoder())
|
|
|
.addLast("encoder", new StringEncoder())
|
|
|
- .addLast(new IdleStateHandler(0, 0, 5))
|
|
|
+ .addLast(new IdleStateHandler(0, 5, 0))
|
|
|
.addLast(backgroundClientHandler);
|
|
|
}
|
|
|
});
|
|
@@ -63,7 +65,7 @@ public class BackgroundClientNetty {
|
|
|
channel = future1.channel();
|
|
|
log.info("后端服务器连接成功,{},{}",config.getHost(), config.getPort());
|
|
|
} else {
|
|
|
- log.error("------------后端-连接服务器失败,{},{}-----------,进行重连",config.getHost(), config.getPort());
|
|
|
+ log.error("-------------后端连接服务器失败,{},{}-----------,进行重连",config.getHost(), config.getPort());
|
|
|
future1.channel().eventLoop().schedule(this::connect, 5, TimeUnit.SECONDS);
|
|
|
}
|
|
|
});
|