JAVA网络学习-netty(1)
netty
Tsukiyo
March 8, 2022 2 min read 416

The original body of this article is written in Chinese.
这里是个helloworld的demo 每行均有注释
这是服务器端
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.channel.nio.NioEventLoop;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.sctp.nio.NioSctpServerChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.string.StringDecoder;
public class Server {
public static void main(String[] args) {
new ServerBootstrap()//启动器负责启动netty组件
.group(new NioEventLoopGroup())//负责分配一个EventLoopGroup(相当于一个selector与channel结合)
.channel(NioServerSocketChannel.class)//服务器的ServerSocketChannel,做的事套接字类似的工作
//负责处理读写
.childHandler(
//代表客户端对数据读写通道的初始化
new ChannelInitializer<NioSocketChannel>() {
@Override
protected void initChannel(NioSocketChannel nioSocketChannel) Exception {
nioSocketChannel.pipeline().addLast( ());
nioSocketChannel.pipeline().addLast( <String>() {
Exception {
System.out.println(s);
}
});
}
}).bind();
}
}
You may also like
All writing
Code Notes
Code Notes·5 min read
@Retryable 注解的使用与深度原理解析
它在 Spring 的 AOP(面向切面编程)机制的支持下,能够在方法执行失败时,根据指定的策略自动重试。注解时,Spring 会自动创建一个代理对象(proxy),并在调用目标方法时,通过拦截器(Interceptor)拦截方法的调用。,它将会自动重试,最多重试 3 次,每次重试之间的延迟时间为 2 秒,且每次重试的延迟时间会按 1.5 倍增长。:过于频繁

Leave a light on
00 repliesNo one has spoken yet. You can be the first light.