java - ChannelInboundMessageHandlerAdapter 找不到符号

标签 java netbeans netty

我尝试以此为基础制作简单的聊天程序 example .

import io.netty.channel.ChannelHandlerContext;

public class ChatClientHandler extends ChannelInboundMessageHandlerAdapter<String>
{

}

我收到找不到符号错误。我也尝试将 SimpleInboundHandlerAdapter 更改为 SimpleInboundHandlerAdapter 但结果相同。

最佳答案

ChannelInboundMessageHandlerAdapter 类在最新版本中不可用。 如果你想使用 ChannelInboundMessageHandlerAdapter 无论如何你必须更新 netty 版本到 4.0.0.CR3 在 Maven 中,您必须添加以下依赖项才能使用此类

<!-- https://mvnrepository.com/artifact/io.netty/netty-all -->
   <dependency>
     <groupId>io.netty</groupId>
     <artifactId>netty-all</artifactId>
     <version>4.0.0.CR3</version>
</dependency>

或者更好的是,您可以升级到最新的稳定版本。此时此刻是4.1.5.Final ...

<dependency>
    <groupId>io.netty</groupId>
    <artifactId>netty-all</artifactId>
    <version>4.1.5.Final</version>
</dependency>

并扩展了 SimpleChannelInboundHandler 而不是 ChannelInboundMessageHandlerAdapter,如下所示:

public class ChatClientHandler extends SimpleChannelInboundHandler<String> {

@Override
protected void channelRead0(ChannelHandlerContext ctx, String msg) throws Exception {
    System.out.println("Te fuiste para lo de Visconti: " + msg);
}

请记住,channelRead0 方法名称将在 5.0 版本中重命名为 messageReceived(ChannelHandlerContext, I)

关于java - ChannelInboundMessageHandlerAdapter 找不到符号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22378513/

相关文章:

java - Netty 如何使用线程池?

java - 使用java将字符串拆分为单词和标点符号

java - Java 新手 - 试图理解 : checker |= (1 << val)

javascript - 在我的网页上尝试编辑器

java - Netbeans 将 root 设置为作者

Java - 在 Netbeans IDE 中将毫秒转换为 `HH:mm:ss:SSS` 时结果不正确

Netty 4 - 直接将ByteBuf写入 channel ,绕过管道

java - 有什么好的框架可以自动测试 AWT GUI 吗?

java - 更改Java中某种类型的所有对象的属性

java - Netty channel 生命周期