riku
2021-03-01 09f411e381f885619b32e05fc89cad26bb20824d
src/main/kotlin/com/flightfeather/uav/socket/ServerHandler.kt
@@ -10,16 +10,23 @@
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)
    }
@@ -29,10 +36,10 @@
        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()
@@ -49,7 +56,7 @@
        }
        val str = sb.toString()
        if (str.isNotEmpty()) {
            MessageManager().dealStringMsg(str, ctx)
            messageManager.dealStringMsg(str, ctx)
        }
    }
@@ -59,7 +66,7 @@
    }
    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)
    }