From 4d44ed185203088052b10a8d1e3526fcbbc88331 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期日, 15 九月 2019 18:42:31 +0800 Subject: [PATCH] obd 数据解码逻辑完成 --- src/main/kotlin/com/flightfeather/obd/socket/SocketServerClient.kt | 14 ++++++++++---- 1 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/obd/socket/SocketServerClient.kt b/src/main/kotlin/com/flightfeather/obd/socket/SocketServerClient.kt index 4c1f489..991a4e7 100644 --- a/src/main/kotlin/com/flightfeather/obd/socket/SocketServerClient.kt +++ b/src/main/kotlin/com/flightfeather/obd/socket/SocketServerClient.kt @@ -4,10 +4,12 @@ import io.netty.channel.ChannelInitializer import io.netty.channel.ChannelOption import io.netty.channel.nio.NioEventLoopGroup -import io.netty.channel.socket.SocketChannel import io.netty.channel.socket.nio.NioServerSocketChannel import io.netty.channel.socket.nio.NioSocketChannel +import io.netty.handler.codec.bytes.ByteArrayDecoder +import io.netty.handler.codec.bytes.ByteArrayEncoder import io.netty.handler.codec.string.StringDecoder +import io.netty.handler.codec.string.StringEncoder /** * socket闀胯繛鎺ユ湇鍔$ @@ -34,15 +36,19 @@ return ServerBootstrap() .group(bossGroup, workerGroup) .channel(NioServerSocketChannel::class.java) + .option(ChannelOption.SO_BACKLOG, 128) + .childOption(ChannelOption.SO_KEEPALIVE, true) + .childOption(ChannelOption.TCP_NODELAY, true) .childHandler(object : ChannelInitializer<NioSocketChannel>() { override fun initChannel(p0: NioSocketChannel?) { p0?.pipeline() - ?.addLast(StringDecoder()) +// ?.addLast("decoder", StringDecoder()) +// ?.addLast("encoder", StringEncoder()) + ?.addLast(ByteArrayDecoder()) + ?.addLast(ByteArrayEncoder()) ?.addLast(ServerHandler()) } }) - .option(ChannelOption.SO_BACKLOG, 128) - .childOption(ChannelOption.SO_KEEPALIVE, true) } catch (e: Throwable) { e.printStackTrace() } -- Gitblit v1.9.3