java - 如何使 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
我希望我的处理程序能够接收消息,但它什么也没做
解决方案
固定的。我太笨了,我只是在其他模块中分配了不同的处理程序,没有调试
推荐阅读
- aws-lambda - 使用 AWS Cognito JWT 令牌进行身份验证时,我是否需要 API Gateway 中的自定义授权方?
- components - 如何通过角度 6 中的单击事件将值获取到组件文件中
- reactjs - 对于由 create-react-app 引导的项目,将测试放在 src 文件夹中的合法性
- ruby-on-rails - Bootstrap-rubygem 与 twitter-bootstrap-rails gem
- google-api-java-client - 服务帐号和 Google Play 开发者 API
- oauth - 是否可以在 Azure Active Directory 的应用程序注册中设置固定范围/资源,而不是让客户端提供这个?
- amazon-web-services - AWS 上的 SSL 安装
- spring-boot - spring zuul中基于严格匹配的路由匹配
- python - 使用 lstm 进行 imdb 评论获得非常低的准确性
- ios - 模拟中的子视图没有那么大