package com.flightfeather.uav.socket.handler
|
|
import io.netty.channel.ChannelHandlerContext
|
import io.netty.channel.ChannelInboundHandlerAdapter
|
import java.text.SimpleDateFormat
|
import java.util.*
|
|
/**
|
* socket消息处理积基类
|
* @date 2025/5/13
|
* @author feiyu02
|
*/
|
abstract class BaseHandler : ChannelInboundHandlerAdapter() {
|
|
abstract var tag: String
|
|
override fun channelRegistered(ctx: ChannelHandlerContext?) {
|
println("------【${tag}】IP连接:[ip:${ctx?.channel()?.remoteAddress()}] ${
|
SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(
|
Date()
|
)}")
|
}
|
|
override fun channelActive(ctx: ChannelHandlerContext?) {
|
println("------【${tag}】IP激活:[ip:${ctx?.channel()?.remoteAddress()}] ${
|
SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(
|
Date()
|
)}")
|
}
|
|
override fun channelRead(ctx: ChannelHandlerContext?, msg: Any?) {
|
println("------【${tag}】收到的原始数据:[ip:${ctx?.channel()?.remoteAddress()}] ${
|
SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(
|
Date()
|
)}")
|
}
|
|
override fun channelInactive(ctx: ChannelHandlerContext?) {
|
println("------【${tag}】端口有IP不活动:[ip:${ctx?.channel()?.remoteAddress()}] ${
|
SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(
|
Date()
|
)}")
|
}
|
|
@Deprecated("Deprecated in Java")
|
override fun exceptionCaught(ctx: ChannelHandlerContext?, cause: Throwable?) {
|
cause?.printStackTrace()
|
ctx?.close()
|
}
|
}
|