|
@@ -4,7 +4,10 @@ import java.net.InetSocketAddress;
|
|
|
|
|
|
import com.persagy.cameractl.conf.AllStaticConfig;
|
|
|
|
|
|
+import ch.qos.logback.core.encoder.ByteArrayUtil;
|
|
|
import io.netty.bootstrap.Bootstrap;
|
|
|
+import io.netty.buffer.ByteBuf;
|
|
|
+import io.netty.buffer.Unpooled;
|
|
|
import io.netty.channel.Channel;
|
|
|
import io.netty.channel.ChannelFuture;
|
|
|
import io.netty.channel.ChannelFutureListener;
|
|
@@ -13,9 +16,6 @@ import io.netty.channel.EventLoopGroup;
|
|
|
import io.netty.channel.nio.NioEventLoopGroup;
|
|
|
import io.netty.channel.socket.SocketChannel;
|
|
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
|
|
-import io.netty.handler.codec.string.StringDecoder;
|
|
|
-import io.netty.handler.codec.string.StringEncoder;
|
|
|
-import io.netty.util.CharsetUtil;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
|
/**
|
|
@@ -51,8 +51,6 @@ public class IotSocketClient {
|
|
|
@Override
|
|
|
protected void initChannel(SocketChannel ch) throws Exception {
|
|
|
log.info("正在连接中...");
|
|
|
- ch.pipeline().addLast(new StringEncoder(CharsetUtil.UTF_8));
|
|
|
- ch.pipeline().addLast(new StringDecoder(CharsetUtil.UTF_8));
|
|
|
ch.pipeline().addLast(new IotClientHandler());
|
|
|
}
|
|
|
});
|
|
@@ -95,7 +93,9 @@ public class IotSocketClient {
|
|
|
log.info("发送数据至服务端: [{}]", message);
|
|
|
|
|
|
try {
|
|
|
- channel.writeAndFlush(message);
|
|
|
+ ByteBuf bufff = Unpooled.buffer();
|
|
|
+ bufff.writeBytes(ByteArrayUtil.hexStringToByteArray(message));
|
|
|
+ channel.writeAndFlush(bufff);
|
|
|
} catch (Exception e) {
|
|
|
log.error("发送数据异常", e);
|
|
|
channel.close();
|