master
masong 2 years ago
parent a713d1e189
commit 00ff104f0b
  1. 3
      src/main/java/com/cjy/iot/netty/server/NettyServerHandler.java

@ -99,6 +99,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
log.info("加载客户端报文,客户端id{},客户端消息:{}", ctx.channel().id(), msg);
String data = String.valueOf(msg);
log.info("消息内容:{}", data);
RabbitTemplate rabbitTemplate = SpringBeanFactory.getBean(RabbitTemplate.class);
@ -210,7 +211,7 @@ public class NettyServerHandler extends ChannelInboundHandlerAdapter {
ByteBuf buffer = Unpooled.buffer();
log.info("开始发送报文:{}", msg);
byte[] bytes = msg.getBytes(StandardCharsets.UTF_8);
buffer.writeBytes(msgBytes);
buffer.writeBytes(bytes);
channel.writeAndFlush(buffer).addListener((ChannelFutureListener) future -> {
if (future.isSuccess()) {
log.info("客户端:{},回写成功:{}", channelId, Arrays.toString(msgBytes));

Loading…
Cancel
Save