读书人

netty的个人应用心得

发布时间: 2013-03-26 09:54:34 作者: rapoo

netty的个人使用心得

?????????????
???????????? //创建 赋值结束的 Build? 并生成 MessageInfo对象?
???????????? MessageInfo messageInfo = builder.build();?
???????????? //将messageInfo转换为字节?
???????????? byte[] messageByte = messageInfo.toByteArray();?
?????????????
???????????? //获得此对象的长度?
???????????? ChannelBuffer channelBuffer = ChannelBuffers.buffer(messageByte.length);?
???????????? //将 获得到的数组写入 channelBuffer中?
???????????? channelBuffer.writeBytes(messageByte);?
???????????? //发送到服务器端?
???????????? for(int i = 0; i < 10;i++){?
???????????? lastWriteFuture = channel.write(channelBuffer);?
???????????? }?
???????????? if (lastWriteFuture != null) {?
????????????? lastWriteFuture.awaitUninterruptibly();?
????????? }?
??????? // }?
??????? //???? Thread.sleep(50000);?
???????? // Wait until all messages are flushed before closing the channel.?
????????
??????????? Thread.sleep(50000);?
???????? // Close the connection.? Make sure the close operation ends because?
???????? // all I/O operations are asynchronous in Netty.?
???????? channel.close().awaitUninterruptibly();?

???????? // We should shut down all thread pools here to exit normally.?
???????? // However, it is just fine to call System.exit(0) because we are?
???????? // finished with the business.?
???????? System.exit(0);?
}?
}?

读书人网 >互联网

热点推荐