package springboot.client; import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelFuture; import io.netty.channel.ChannelOption; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.nio.NioSocketChannel; import springboot.client.handler.HttpClientInitializer; import java.net.InetSocketAddress; public class HttpClient { public void start() throws Exception{ EventLoopGroup group = new NioEventLoopGroup(); try { Bootstrap bootstrap = new Bootstrap(); bootstrap.group(group) .channel(NioSocketChannel.class) .option(ChannelOption.TCP_NODELAY, true) .handler(new HttpClientInitializer()); // 发起异步连接 ChannelFuture future = bootstrap.connect(new InetSocketAddress("127.0.0.1", 3560)); // 当客户端链路关闭 future.channel().closeFuture().sync(); }finally { // 优雅退出,释放NIO线程组 group.shutdownGracefully(); } } public static void main(String args[])throws Exception{ new HttpClient().start(); } }
最近下载更多
zhouenyi LV6
3月20日
酒酒清欢 LV8
2023年12月5日
微信网友_6724618780348416 LV3
2023年12月4日
yqyqyqyqy LV4
2023年7月23日
3416059514 LV1
2023年6月23日
try8023 LV18
2023年5月4日
ycyycy LV1
2022年10月24日
zxc131313 LV12
2022年10月22日
微信网友_6152246112423936 LV1
2022年9月28日
xingbing LV9
2022年9月5日