netty
chrislin9
这个作者很懒,什么都没留下…
展开
-
netty系列四 Bootstrap
netty Bootstrap类 Bootstrap类的方法 从Channel引导客户端 通过将已被接受的子Channel的EventLoop传递给Bootstrap 的group()方法来共享该EventLoop。因为分配给EventLoop的所有Channel都使用同一 个线程,所以这避免了额外的线程创建,以及前面所提到的相关的上下文切换。这个共享的解决 方案如图 8-4 所示。 Ser...原创 2020-01-21 09:46:23 · 167 阅读 · 0 评论 -
netty系列三 ByteBuf
简介 字节是网络数据的基本单位。 Java NIO 提供了 ByteBuffer 作为字节容器,但是这个类使用起来过于复杂,而且也有些繁琐。Netty使用了即易于使用又具备良好性能的ByteBuf来替代ByteBuffer。 使用模式 堆缓冲区 直接缓冲区 复合缓冲区 堆缓冲区 ——>JVM 的堆空间 最常用的 ByteBuf 模式是将数据存储在 JVM 的堆空间中。这种模式被称为支撑...原创 2020-01-20 15:07:09 · 230 阅读 · 0 评论 -
netty系列二 Handler
netty常用内置Handler IdleStateHandler new IdleStateHandler(this.readerIdleTime, this.writerIdleTime, this.allIdleTime, this.timeUnit)) readerIdleTime 读取时间 writerIdleTime 写时间 timeUnit 读+写总共时间 根据你设置的超时参数...原创 2020-01-16 17:00:18 · 623 阅读 · 0 评论 -
netty nio 示例
1 public class HttpServer { int port ; public HttpServer(int port){ this.port = port; } public void start() throws Exception{ ServerBootstrap bootstrap = new ServerBoot...原创 2020-01-19 13:59:25 · 119 阅读 · 1 评论 -
netty系列一 入门
1 netty的应用场景 netty的应用场景 netty可以应用于各种协议: netty可用作rpc的通信框架 netty可用作长连接的服务器(webSocket) netty也可作为http的服务器 webSocket中: 客户端与服务端交互不需要遵循"请求-响应"的模式,可以服务端主动向客户端发送消息。 发送的消息可以不遵循"header-body"的格式,可以自定义格式 浏览器自动发出两...原创 2020-01-16 13:43:52 · 119 阅读 · 0 评论