| | |
| | | package com.flightfeather.obd.socket |
| | | |
| | | import com.flightfeather.obd.domain.entity.ObdData |
| | | import com.google.gson.Gson |
| | | import io.netty.channel.ChannelHandler |
| | | import io.netty.channel.ChannelHandlerContext |
| | | import io.netty.channel.ChannelInboundHandlerAdapter |
| | | import io.netty.util.AttributeKey |
| | | |
| | | |
| | | class ServerHandler : ChannelInboundHandlerAdapter() { |
| | | |
| | |
| | | |
| | | override fun channelRead(ctx: ChannelHandlerContext?, msg: Any?) { |
| | | super.channelRead(ctx, msg) |
| | | val attribute = ctx?.channel()?.attr(attributeKey)?.apply { |
| | | if (get() == null) { |
| | | // set() |
| | | } |
| | | 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?) { |
| | |
| | | } |
| | | |
| | | override fun exceptionCaught(ctx: ChannelHandlerContext?, cause: Throwable?) { |
| | | super.exceptionCaught(ctx, cause) |
| | | cause?.printStackTrace() |
| | | ctx?.close() |
| | | } |
| | | } |