
#netty
Be_With_I
这个作者很懒,什么都没留下…
展开
-
netty组件介绍1
Bootstrap 和 ServerBootstrap 配置的引导对象EventLoopGroup 线程组Channel 就是服务器端的通道handler 方法和 给boss 那个组的配置childHandler方法的区别。给work那个组的配置future 和 channelFuture 可以注册想赢的监听, 因为服务端都是异步的。...原创 2020-02-07 23:48:35 · 130 阅读 · 0 评论 -
netty 中ByteBuf 的api
主要用于存取数据package netty;import io.netty.buffer.ByteBuf;import io.netty.buffer.Unpooled;import java.nio.charset.Charset;public class Buf02{ public static void main(String[] args) { B...原创 2020-02-07 08:39:40 · 197 阅读 · 0 评论 -
netty Unpooled 工具类
常规使用package netty;import io.netty.buffer.ByteBuf;import io.netty.buffer.Unpooled;public class BufDemo { public static void main(String[] args) { ByteBuf buffer = Unpooled.buffer(10);...原创 2020-02-06 23:47:57 · 491 阅读 · 0 评论 -
netty 5-1 用netty写一个可以用http请求的服务
代码如下serverpackage http;import io.netty.bootstrap.ServerBootstrap;import io.netty.channel.ChannelFuture;import io.netty.channel.nio.NioEventLoopGroup;import io.netty.channel.socket.nio.NioServer...原创 2020-01-19 14:49:55 · 338 阅读 · 0 评论 -
netty 4-3 注册一个ChannelFuture
代码如下 在Server中加入下边的代码即可 ChannelFuture channelFuture = serverBootstrap.bind(6677).sync(); channelFuture.addListener(new ChannelFutureListener() { @Override ...原创 2020-01-19 13:25:35 · 149 阅读 · 0 评论 -
netty 4-2 定时任务
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { //比如这里我们有一个非常费时的操作。将其弄到NioEventLoop中的queue中就可以了// Thread.sleep(10*1000);// ctx.writeAndFlush(U...原创 2020-01-19 10:37:37 · 600 阅读 · 0 评论 -
netty 4-1 如果服务端需要长时间的处理。我们可以通过queue处理
只需要修改handler中的read方法 前两行注释的是第一种情况,这中会阻塞。代码中是会开启一个新的线程执行,taskQueue 中会有两条数据。这两个是在一个线程中的要顺序执行 一共三十秒 @Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ...原创 2020-01-19 10:18:43 · 212 阅读 · 0 评论 -
netty 4*写一个简单的客户端和服务端。 自己的handler
服务端代码如下package netty;import io.netty.bootstrap.ServerBootstrap;import io.netty.channel.*;import io.netty.channel.nio.NioEventLoopGroup;import io.netty.channel.socket.SocketChannel;import io.net...原创 2020-01-18 13:47:20 · 263 阅读 · 0 评论 -
netty ?-32 用NIO来实现简单的群聊系统
Client 代码如下package chat;import java.io.IOException;import java.net.InetSocketAddress;import java.net.SocketAddress;import java.nio.ByteBuffer;import java.nio.channels.SelectionKey;import java....原创 2020-01-15 18:04:17 · 413 阅读 · 0 评论 -
netty 20-30
主要是Selector 有几个方法这个就是类似一个监听器selector 方法,就是阻塞监听 channel上的变化 ,有变化的都返回 selectkeys有等确定事件的方法now 有立刻返回的方法利用NIO写一个Server 和 Client 的通讯package nio;import java.io.IOException;import java.net.InetSock...原创 2020-01-14 16:55:01 · 102 阅读 · 0 评论 -
netty 11-20 利用Buffer 和Channel 和ServerSocketChannel进行文件的复制,也就是读写,以及网络传输
用FileChanel 将字符串写入本地磁盘:package nio;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.OutputStream;import java.nio.ByteBuffer;import java.nio.channels.FileChann...原创 2020-01-13 23:26:37 · 283 阅读 · 0 评论 -
netty 1-10 主要是BIO 和 NIO 结构,及主要组成 区别
就是像装饰器模式一样,一层一层的增强。2,说的是netty 主要作用,基于事件的网络通信。原创 2020-01-10 22:51:25 · 139 阅读 · 0 评论