【发布时间】:2015-03-18 15:29:51
【问题描述】:
我从事网络编程已经有一段时间了,最近将我的一个项目转换为 netty。与我的原始程序不同,客户端将在关闭前冻结大约 3-5 秒,这足以让我最终每次都强制终止它,因为我不想等待它。这对netty来说是正常的吗?难道我做错了什么?
主要方法:
public static void main(String[] args) throws Exception {
final SslContext sslCtx = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);
EventLoopGroup group = new NioEventLoopGroup();
try {
Bootstrap b = new Bootstrap();
b.group(group)
.channel(NioSocketChannel.class)
.handler(new NetworkInitializer(sslCtx));
// Start the connection attempt.
ch = b.connect(HOST, PORT).sync().channel();
//sends the clients name to the server
askname();
//loop just does some simple gl stuff and gameplay updating, posted below
while(running){loop();
if (Display.isCloseRequested()){
running = false;
if (lastWriteFuture != null) {
lastWriteFuture.sync();
} //tells the server to shut down
write("9");
ch.closeFuture().sync();
group.shutdownGracefully();
System.out.println("herro der");
break;
}
}
} finally {
group.shutdownGracefully();
// The connection is closed automatically on shutdown.
}
}
循环类:
private static void loop() {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
//main update method for my game. does calculations and stuff. I can post it if neccisary but its kinda big.
SpaceState.update();
Display.update();
Display.sync(60);
}
【问题讨论】:
-
Java 8 有机会吗?看到了同样的事情。不是 netty 特定的,也没有在 Java 7/6 中观察到相同的代码。
标签: netty