| | |
| | | |
| | | class ServerHandler : ChannelInboundHandlerAdapter() { |
| | | |
| | | companion object { |
| | | private const val TAG = "UAV" |
| | | } |
| | | |
| | | val attributeKey = AttributeKey.valueOf<String>("deviceCode") |
| | | val messageManager = MessageManager() |
| | | |
| | | override fun channelRegistered(ctx: ChannelHandlerContext?) { |
| | | super.channelRegistered(ctx) |
| | | println("------端口有IP连接:[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") |
| | | println() |
| | | println("------${TAG}端口有IP连接:[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") |
| | | // ctx?.fireChannelActive() |
| | | } |
| | | |
| | | override fun channelActive(ctx: ChannelHandlerContext?) { |
| | | println("------端口有IP激活:[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") |
| | | println() |
| | | println("------${TAG}端口有IP激活:[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") |
| | | super.channelActive(ctx) |
| | | } |
| | | |
| | |
| | | val sb = StringBuilder() |
| | | |
| | | if (msg is ByteArray) { |
| | | println("------收到的原始数据:[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") |
| | | println() |
| | | println("------${TAG}收到的原始数据:[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") |
| | | msg.forEach { |
| | | var a = 0 |
| | | a = if (it < 0) { |
| | | val a: Int = if (it < 0) { |
| | | it + 256 |
| | | } else { |
| | | it.toInt() |
| | |
| | | } |
| | | val str = sb.toString() |
| | | if (str.isNotEmpty()) { |
| | | MessageManager().dealStringMsg(str, ctx) |
| | | messageManager.dealStringMsg(str, ctx) |
| | | } |
| | | |
| | | } |
| | |
| | | } |
| | | |
| | | override fun channelInactive(ctx: ChannelHandlerContext?) { |
| | | println("------端口有IP不活动:[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") |
| | | println("------${TAG}端口有IP不活动:[ip:${ctx?.channel()?.remoteAddress()}] ${SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(Date())}") |
| | | super.channelInactive(ctx) |
| | | } |
| | | |