怎么用netty搭建一个websocket的java客户端 10
2个回答
展开全部
HttpRequestHandler -- HTTP请求处理类
TextWebSocketFrameHandler -- 对应Text消息的处理类
WebSocketServer -- 系统主类
WebSocketServerInitializer -- 服务主程序的初始化类
WebSocketServer 类代码:
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
public final class WebSocketServer {
private int port = 0;
public WebSocketServer(int port) {
this.port = port;
}
TextWebSocketFrameHandler -- 对应Text消息的处理类
WebSocketServer -- 系统主类
WebSocketServerInitializer -- 服务主程序的初始化类
WebSocketServer 类代码:
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;
public final class WebSocketServer {
private int port = 0;
public WebSocketServer(int port) {
this.port = port;
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询