首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 互联网 >

netty的个人应用心得

2013-03-26 
netty的个人使用心得????????????????????????? //创建 赋值结束的 Build? 并生成 MessageInfo对象???????

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);?
}?
}?

热点排行