首页 > 解决方案 > 如何使 MINA 客户端消息事件触发?

问题描述

我正在制作一个需要客户端-服务器消息传递的应用程序。我决定使用 MINA。服务器工作得很好(读取消息、触发事件和写入响应,如在日志中),但客户端似乎没有触发任何事件。它记录发送的消息、接收的字节,但从不使用处理程序。处理程序内的任何调试消息都不会被打印。如何使 messageReceived 事件触发?

我正在使用带有 1.8.0_212 java、MINA 版本 2.1.2、Kotlin 版本 1.3.30 的 Linux 服务器

val connector = NioSocketConnector()

connector.filterChain.addLast("logger", LoggingFilter())
connector.filterChain.addLast("codec", ProtocolCodecFilter(TextLineCodecFactory(Charsets.UTF_8, System.lineSeparator(), System.lineSeparator())))

connector.handler = object: IoHandlerAdapter() {
    override fun sessionCreated(session: IoSession?)
        println("created session")
    }

    override fun event(session: IoSession?, event: FilterEvent) {
        println("event: ${event::class.java.simpleName}")
    }

    override fun messageReceived(session: IoSession?, message: Any) {
        println("received message: $message")
    }
}

val future = lobbyConnector.connect(InetSocketAddress("172.18.0.10",
Constants.SERVER_PORT))
future.awaitUninterruptibly()

val session = future.session
session.config.isUseReadOperation = true

我希望我的处理程序能够接收消息,但它什么也没做

标签: javakotlinioapache-mina

解决方案


固定的。我太笨了,我只是在其他模块中分配了不同的处理程序,没有调试


推荐阅读