Commit 884e7b9d authored by duanruiming's avatar duanruiming

[update] 代码优化

parent 2cf9aad7
...@@ -49,18 +49,18 @@ public class NettyClient { ...@@ -49,18 +49,18 @@ public class NettyClient {
@Override @Override
protected void initChannel(NioSocketChannel socketChannel) { protected void initChannel(NioSocketChannel socketChannel) {
log.info("新增客户端连接ip:{},port:{}", socketChannel.remoteAddress().getHostString(), socketChannel.remoteAddress().getPort()); log.info("新增客户端连接ip:{},port:{}", socketChannel.remoteAddress().getHostString(), socketChannel.remoteAddress().getPort());
socketChannel.writeAndFlush("2a320d0a24340d0a415554480d0a2431360d0a536d2a674234504742333939514241390d0a");
log.info("发送密码。。。"); log.info("发送密码。。。");
socketChannel.pipeline() socketChannel.pipeline()
.addLast(new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, Integer.MAX_VALUE, 4, 2, 0, 0, true)) .addLast(new LengthFieldBasedFrameDecoder(ByteOrder.LITTLE_ENDIAN, Integer.MAX_VALUE, 4, 2, 0, 0, true))
.addLast(new NettyServerHandler(threadPoolExecutor)); .addLast(new NettyServerHandler(threadPoolExecutor));
channelGroup.add(socketChannel); channelGroup.add(socketChannel);
socketChannel.writeAndFlush("2a320d0a24340d0a415554480d0a2431360d0a536d2a674234504742333939514241390d0a");
String key = StringUtils.join(socketChannel.remoteAddress().getHostString(), ":".intern(), socketChannel.remoteAddress().getPort()); String key = StringUtils.join(socketChannel.remoteAddress().getHostString(), ":".intern(), socketChannel.remoteAddress().getPort());
IP_PORT_CHANNEL_ID_MAP.put(key, socketChannel.id()); IP_PORT_CHANNEL_ID_MAP.put(key, socketChannel.id());
log.info("{}:客户端连接成功", key); log.info("{}:客户端连接成功", key);
} }
}); });
ChannelFuture channelFuture = bootstrap.bind(localPort).sync(); ChannelFuture channelFuture = bootstrap.bind(remotePort).sync();
log.info("server is started in {}", channelFuture.channel().localAddress()); log.info("server is started in {}", channelFuture.channel().localAddress());
//收到停止信号 //收到停止信号
Runtime.getRuntime().addShutdownHook(new Thread(() -> { Runtime.getRuntime().addShutdownHook(new Thread(() -> {
......
...@@ -9,7 +9,6 @@ import net.wanji.com.netty.pojo.CommandPojo; ...@@ -9,7 +9,6 @@ import net.wanji.com.netty.pojo.CommandPojo;
import net.wanji.com.netty.response.CommandResponseService; import net.wanji.com.netty.response.CommandResponseService;
import net.wanji.com.pojo.netty.MessageResultPojo; import net.wanji.com.pojo.netty.MessageResultPojo;
import net.wanji.com.util.CRC16Utils; import net.wanji.com.util.CRC16Utils;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
/** /**
...@@ -28,7 +27,7 @@ public class HeartBeatService implements CommandResponseService { ...@@ -28,7 +27,7 @@ public class HeartBeatService implements CommandResponseService {
return heartBeatRequest; return heartBeatRequest;
} }
@Scheduled(fixedRate = 1000) // @Scheduled(fixedRate = 1000)
public void heartbeat() { public void heartbeat() {
String body = String.format("%02x", Constants.COMMAND_HEARTBEAT.length() / 2).concat(Constants.COMMAND_HEARTBEAT); String body = String.format("%02x", Constants.COMMAND_HEARTBEAT.length() / 2).concat(Constants.COMMAND_HEARTBEAT);
String crc16HexStr = CRC16Utils.getCRC16HexStr(body); String crc16HexStr = CRC16Utils.getCRC16HexStr(body);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment