我尝试以此为基础制作简单的聊天程序 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/