riku
2019-09-05 28b10b7255483c8e2eb5e3e828f8cda658e94c44
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()
    }
}