From a0694aba52b4fb590039ff69e1625938ebef1041 Mon Sep 17 00:00:00 2001 From: riku <risaku@163.com> Date: 星期三, 11 九月 2019 16:19:22 +0800 Subject: [PATCH] 1.新增用户信息的获取存储接口 --- src/main/kotlin/com/flightfeather/obd/socket/ServerHandler.kt | 18 +++++++++++++----- 1 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/main/kotlin/com/flightfeather/obd/socket/ServerHandler.kt b/src/main/kotlin/com/flightfeather/obd/socket/ServerHandler.kt index e1480ee..a71b02e 100644 --- a/src/main/kotlin/com/flightfeather/obd/socket/ServerHandler.kt +++ b/src/main/kotlin/com/flightfeather/obd/socket/ServerHandler.kt @@ -4,6 +4,7 @@ import io.netty.channel.ChannelInboundHandlerAdapter import io.netty.util.AttributeKey + class ServerHandler : ChannelInboundHandlerAdapter() { val attributeKey = AttributeKey.valueOf<String>("deviceCode") @@ -18,11 +19,17 @@ override fun channelRead(ctx: ChannelHandlerContext?, msg: Any?) { super.channelRead(ctx, msg) - val attribute = ctx?.channel()?.attr(attributeKey)?.apply { - if (get() == null) { -// set() - } + println("------鏀跺埌鐨勫師濮嬫暟鎹細[ip:${ctx?.channel()?.remoteAddress()}]\r\n$msg") + if (msg is String) { + MessageManager().dealMsg(msg, ctx) } + +// val attribute = ctx?.channel()?.attr(attributeKey)?.apply { +// if (get() == null) { +// set(data.obdVin) +// } +// } + } override fun channelReadComplete(ctx: ChannelHandlerContext?) { @@ -34,6 +41,7 @@ } override fun exceptionCaught(ctx: ChannelHandlerContext?, cause: Throwable?) { - super.exceptionCaught(ctx, cause) + cause?.printStackTrace() + ctx?.close() } } \ No newline at end of file -- Gitblit v1.9.3