Java 无法从类io.netty.Channel.sctp.nio.NioSctpChannel创建通道
我正在尝试使用netty创建聊天应用程序。当我尝试运行聊天客户端时,我启动了chatserver java应用程序。它表明Java 无法从类io.netty.Channel.sctp.nio.NioSctpChannel创建通道,java,netty,Java,Netty,我正在尝试使用netty创建聊天应用程序。当我尝试运行聊天客户端时,我启动了chatserver java应用程序。它表明 线程“main”io.netty.channel.ChannelException中出现异常:无法 从类创建通道的步骤 io.netty.channel.sctp.nio.NIOSCTPTCHANNEL at io.netty.channel.ReflectiveChannelFactory.newChannel (ReflectVechannelFactory.java
- 线程“main”io.netty.channel.ChannelException中出现异常:无法 从类创建通道的步骤 io.netty.channel.sctp.nio.NIOSCTPTCHANNEL at io.netty.channel.ReflectiveChannelFactory.newChannel (ReflectVechannelFactory.java:40)
无法创建频道错误
已被我清除
我自己已经回答了,请帮我解决第二个问题
错误-2:我收到一个名为警告的新错误:初始化频道失败。关闭:[id:0x9e4e05e0]java.lang.ClassCastException:io.netty.channel.sctp.nio.NioSctpChannel无法强制转换为io.netty.channel.socket.SocketChannel
如果需要,这里是github链接。我得到的错误是
无法从类io.netty.Channel创建频道
哪个
是由以下原因引起的:java.lang.UnsupportedOperationException:
ibsctp.so.1:无法打开共享对象文件:没有此类文件或
目录`
通过以下方式安装lksctp工具后,此错误被清除:
sudo-apt-get-install-lksctp-tools
现在频道已经注册了。但我发现了一个新的错误
警告:
初始化通道失败。正在关闭:[id:0x9e4e05e0]
java.lang.ClassCastException:io.netty.channel.sctp.nio.NioSctpChannel
无法强制转换为io.netty.channel.socket.SocketChannel
发生错误的原因是您使用了:
**chatclient.java**
package com.examplechat;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.sctp.nio.NioSctpChannel;
public class ChatClient {
public static void main(String[] args) throws InterruptedException, IOException {
new ChatClient("localhost", 8000).run();
}
private final String host;
private final int port;
public ChatClient(String host, int port) {
super();
this.host = host;
this.port = port;
}
public void run() throws InterruptedException, IOException {
EventLoopGroup group = new NioEventLoopGroup();
try {
Bootstrap bootstrap = new Bootstrap()
.group(group)
.channel(NioSctpChannel.class)
.handler(new ChatClientInitilizer());
Channel channel = bootstrap.connect(host, port).sync().channel();
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
while(true) {
channel.write(in.readLine()+ "\r\n");
}
}
finally {
group.shutdownGracefully(); }
}
}
**ChatServer.java**
package com.examplechat;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
public class ChatServer {
public static void main(String[] args) throws InterruptedException {
new ChatServer(8000).run();
}
private final int port;
public ChatServer(int port) {
super();
this.port = port;
}
public void run() throws InterruptedException {
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap bootstrap = new ServerBootstrap()
.group(bossGroup, workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ChatServerInitializer());
bootstrap.bind(port).sync().channel().closeFuture().sync();
}
finally {
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}}
公共类ChatServerInitializer扩展了ChannelInitializer
将其更改为:
public class ChatServerInitializer extends ChannelInitializer<SocketChannel>
公共类ChatServerInitializer扩展了ChannelInitializer
如果您想让我包含其他文件,也请告诉我!非常感谢你,诺曼。它现在甚至可以与其他设备一起工作。我尝试在ChatServer类中使用NioSocketCannel
而不是NioserverSocketCannel
。我试图在您的示例ChatServer应用程序中了解此跟踪项目,我们使用messageReceived
函数在控制台上显示输出,但在下面的链接中,他们使用MainEventHandler.Java
从每个协议的管道接收数据,但他们只在数据库中存储positionID
。我不知道其他细节是如何保存的,你能帮我吗?[
public class ChatServerInitializer extends ChannelInitializer<Channel>