channelfuture sync和wait的区别
答案:2 悬赏:60 手机版
解决时间 2021-03-20 21:57
- 提问者网友:轻浮
- 2021-03-20 13:21
channelfuture sync和wait的区别
最佳答案
- 五星知识达人网友:执傲
- 2021-03-20 13:34
wait
v.等;等待
n.等待;等候
channelfuture sync
请确认是否拼写错误
v.等;等待
n.等待;等候
channelfuture sync
请确认是否拼写错误
全部回答
- 1楼网友:夜余生
- 2021-03-20 13:45
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;
}
public void run() throws exception {
eventloopgroup bossgroup = new nioeventloopgroup();
eventloopgroup workergroup = new nioeventloopgroup();
try {
serverbootstrap b = new serverbootstrap();
b.group(bossgroup, workergroup)
.channel(nioserversocketchannel.class)
.childhandler(new websocketserverinitializer())
.option(channeloption.so_backlog, 128)
.childoption(channeloption.so_keepalive, true);
system.out.println("websocketchatserver 启动了");
// 绑定端口,开始接收进来的连接
channelfuture f = b.bind(port).sync();
// 等待服务器 socket 关闭 。在这个例子中,这不会发生,但你可以优雅地关闭你的服务器。
f.channel().closefuture().sync();
} finally {
workergroup.shutdowngracefully();
bossgroup.shutdowngracefully();
system.out.println("websocketchatserver 关闭了");
}
}
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯