netty-chat | 使用Netty实现IMServer,支持Tcp和WebSocket实现。 | Websocket library
kandi X-RAY | netty-chat Summary
kandi X-RAY | netty-chat Summary
使用Netty实现IMServer,支持Tcp和WebSocket实现。
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Decode packet
- Returns the length of the packet
- Gets the length of the header
- Sets the header length
- Encodes the web socket
- Gets the sequence id
- Gets the message body
- Obtain a connection from a given server
- Returns the key for the given uid
- Starts the server
- Restart the server
- List of operations
- Sends a heartbeat message to the server
- Shutdown channel
- Handle exception
- Update producer
- Starts the worker thread
- Quit a client
- Main application
- The default cache manager
- Performs authentication
- Receives a message
- Method to encode the list
- Handles send operation
- Initialize channel
- Decodes the message body
netty-chat Key Features
netty-chat Examples and Code Snippets
Community Discussions
Trending Discussions on netty-chat
QUESTION
**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();
}
}}
...ANSWER
Answered 2018-Mar-08 at 09:52I was getting error as
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`
This error was cleared once I install lksctp-tools by:
sudo apt-get install lksctp-tools
Now channel has been registered. But I'm getting a new error that 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
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install netty-chat
You can use netty-chat like any standard Java library. Please include the the jar files in your classpath. You can also use any IDE and you can run and debug the netty-chat component as you would do with any other Java program. Best practice is to use a build tool that supports dependency management such as Maven or Gradle. For Maven installation, please refer maven.apache.org. For Gradle installation, please refer gradle.org .
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page