riku
2021-03-01 7a3654aaebf1d75303a90f3dc574881b0199779c
src/main/kotlin/com/flightfeather/uav/socket/ServerHandler.kt
@@ -10,16 +10,22 @@
class ServerHandler : ChannelInboundHandlerAdapter() {
    companion object {
        private const val TAG = "UAV"
    }
    val attributeKey = AttributeKey.valueOf<String>("deviceCode")
    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,7 +35,8 @@
        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 {
                val a: Int = if (it < 0) {
                    it + 256
@@ -58,7 +65,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)
    }