无法从 class io.netty.channel.sctp.nio.NioSctpChannel 创建频道
Unable to create Channel from class io.netty.channel.sctp.nio.NioSctpChannel
**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();
}
}}
I'm trying to create a chat Application using netty. When I try to run the chat client once I initiate chatserver java application. It shows
- 线程异常 "main" io.netty.channel.ChannelException: 无法
从 class class 创建频道
io.netty.channel.sctp.nio.NioSctpChannel 在
io.netty.channel.ReflectiveChannelFactory.newChannel
(ReflectiveChannelFactory.java:40)
我什至更改了 pom.xml 的依赖项,但我每次 运行 时仍然收到相同的错误
Update
Error-1: Unable to create Channel error
has been cleared by myself
我已经自己回答了,请帮我解决第二个问题
Error-2: I'm getting a new error called WARNING: Failed to initialize a channel. Closing: [id: 0x9e4e05e0] java.lang.ClassCastException: io.netty.channel.sctp.nio.NioSctpChannel cannot be cast to io.netty.channel.socket.SocketChannel
这里是 github link 如果你需要 https://github.com/cyborgsri/Chat-Application/tree/master/netty-chat-youtube/src/main/java/com/examplechat.
我遇到错误
Unable to create Channel from class class io.netty.channel
which
is Caused by: java.lang.UnsupportedOperationException:
ibsctp.so.1: cannot open shared object file: No such file or
directory`
我通过以下方式安装 lksctp-tools 后清除了此错误:
sudo apt-get install lksctp-tools
现在频道已经注册。但我收到一个新错误
警告:
Failed to initialize a channel. Closing: [id: 0x9e4e05e0]
java.lang.ClassCastException: io.netty.channel.sctp.nio.NioSctpChannel
cannot be cast to io.netty.channel.socket.SocketChannel
错误发生是因为您使用了:
public class ChatServerInitializer extends ChannelInitializer<SocketChannel>
改为:
public class ChatServerInitializer extends ChannelInitializer<Channel>
**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();
}
}}
I'm trying to create a chat Application using netty. When I try to run the chat client once I initiate chatserver java application. It shows
- 线程异常 "main" io.netty.channel.ChannelException: 无法 从 class class 创建频道 io.netty.channel.sctp.nio.NioSctpChannel 在 io.netty.channel.ReflectiveChannelFactory.newChannel (ReflectiveChannelFactory.java:40)
我什至更改了 pom.xml 的依赖项,但我每次 运行 时仍然收到相同的错误
Update Error-1:
Unable to create Channel error
has been cleared by myself
我已经自己回答了,请帮我解决第二个问题
Error-2: I'm getting a new error called WARNING:
Failed to initialize a channel. Closing: [id: 0x9e4e05e0] java.lang.ClassCastException: io.netty.channel.sctp.nio.NioSctpChannel cannot be cast to io.netty.channel.socket.SocketChannel
这里是 github link 如果你需要 https://github.com/cyborgsri/Chat-Application/tree/master/netty-chat-youtube/src/main/java/com/examplechat.
我遇到错误
Unable to create Channel from class class io.netty.channel
which is Caused by: java.lang.UnsupportedOperationException: ibsctp.so.1: cannot open shared object file: No such file or directory`
我通过以下方式安装 lksctp-tools 后清除了此错误:
sudo apt-get install lksctp-tools
现在频道已经注册。但我收到一个新错误 警告:
Failed to initialize a channel. Closing: [id: 0x9e4e05e0] java.lang.ClassCastException: io.netty.channel.sctp.nio.NioSctpChannel cannot be cast to io.netty.channel.socket.SocketChannel
错误发生是因为您使用了:
public class ChatServerInitializer extends ChannelInitializer<SocketChannel>
改为:
public class ChatServerInitializer extends ChannelInitializer<Channel>