当前位置: 首页 > news >正文

网络营销推广网站收录哪些/韶山百度seo

网络营销推广网站收录哪些,韶山百度seo,wordpress安装主题教程,网站域名后缀区别一 案例 1.1 案例描述 1.netty服务器使用6666端口监听,浏览器发送的请求:http://localhost:6666/ 2.服务器收到消息后,向浏览器发送消息“hello,我是服务器,你在干什么!!!”,并对…

一 案例

1.1 案例描述

1.netty服务器使用6666端口监听,浏览器发送的请求:http://localhost:6666/

2.服务器收到消息后,向浏览器发送消息“hello,我是服务器,你在干什么!!!”,并对特定资源进行过滤。

1.2 代码

1.server端

package com.ljf.netty.netty.http;import com.ljf.netty.netty.tcp.NettyTcpServerHandler3;
import io.netty.bootstrap.ServerBootstrap;
import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelOption;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.SocketChannel;
import io.netty.channel.socket.nio.NioServerSocketChannel;/*** @ClassName: NettyHttpServer* @Description: TODO* @Author: liujianfu* @Date: 2022/05/30 09:10:05* @Version: V1.0**/
public class NettyHttpServer {public static void main(String[] args) {//创建连个线程组bossGroup和workerGroupEventLoopGroup bossGroup=new NioEventLoopGroup(1);//默认为cpu核数*2;EventLoopGroup workGroup=new NioEventLoopGroup();try {//创建服务器端的启动对象,配置参数ServerBootstrap bootstrap=new ServerBootstrap();//使用链式编程来进行设置bootstrap.group(bossGroup,workGroup) //设连个线程组.channel(NioServerSocketChannel.class) //使用NioSocketChannel作为服务器的通道实现// .option(ChannelOption.SO_BACKLOG,128)//设置线程队列得到的连接个数//.childOption(ChannelOption.SO_KEEPALIVE,true)  //设置保持活动连接状态.childHandler(new NettyHttpInitializer());//给我们的workerGroup的EventLopp对应的管道设置处理器,自定义的。System.out.println(".......netty服务器 is ready.....");//启动服务器(并绑定端口)ChannelFuture channelFuture=bootstrap.bind(6666).sync();//对关闭的通道进行监听channelFuture.channel().closeFuture().sync();} catch (InterruptedException e) {e.printStackTrace();}finally {bossGroup.shutdownGracefully();workGroup.shutdownGracefully();}}
}

2.适配器

public class NettyHttpInitializer extends ChannelInitializer<SocketChannel> {@Overrideprotected void initChannel(SocketChannel ch) throws Exception {//向管道加入处理器//得到管道ChannelPipeline pipeline=ch.pipeline();//加入一个解码器,HttpServerCodec 是netty提供的处理http的编-解码器pipeline.addLast("MyHttpServerCodec",new HttpServerCodec());// 增加一个自定义的 handlerpipeline.addLast("MyDefineHandler",new DefineServerHandler());}
}

3.自定义handler

package com.ljf.netty.netty.http;import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.*;
import io.netty.util.CharsetUtil;import java.net.URI;/*** @ClassName: DefineServerHandler* @Description: TODO*    simpleChannelInboundHandler 是 ChannelInboundHandlerAdapter*    HttpObject 客户端和服务器端相互通讯的数据被封装成 HttpObject* @Author: liujianfu* @Date: 2022/05/30 10:55:11* @Version: V1.0**/
public class DefineServerHandler extends SimpleChannelInboundHandler<HttpObject> {// 读取客户端数据@Overrideprotected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {//判断msg 是不是httprequest请求if(msg instanceof HttpRequest){System.out.println("pipeline hashcode:"+ctx.pipeline().hashCode()+" handler hash:"+this.hashCode());System.out.println("msg 类型: "+msg.getClass());System.out.println("客户端地址:"+ctx.channel().remoteAddress());//获取到HttpRequest httpRequest=(HttpRequest)msg;//获取uri,过滤制定的资源URI uri=new URI(httpRequest.uri());ByteBuf content=null;if("/mb".equals(uri.getPath())){System.out.println("请求含有非路径上下文,不能理会....");//回复给浏览器的信息content= Unpooled.copiedBuffer("请求含有非路径上下文,不能理会....", CharsetUtil.UTF_8);// return;}else{//回复给浏览器的信息content= Unpooled.copiedBuffer("hello,我是服务器,你在干什么!!!", CharsetUtil.UTF_8);}//构造一个http的响应,即httpresponseFullHttpResponse response=new DefaultFullHttpResponse(HttpVersion.HTTP_1_1,HttpResponseStatus.OK,content);response.headers().set(HttpHeaderNames.CONTENT_TYPE,"text/plain");response.headers().set(HttpHeaderNames.ACCEPT_CHARSET,"utf-8");response.headers().set(HttpHeaderNames.CONTENT_LENGTH,content.readableBytes());//构建好 responsectx.writeAndFlush(response);}}
}

4.测试结果

 过滤资源

http://www.lbrq.cn/news/1349695.html

相关文章:

  • php 企业网站 后台图片上传/百度我的订单
  • python可以做网站/查域名
  • 网站红色搭配/seo软件简单易排名稳定
  • 微信昵称大全/指定关键词seo报价
  • 网站制作过程简介/超级外链在线发布
  • 网站解析后几天可以访问/自媒体有哪些平台
  • 做问卷调查有哪些网站好/交换友情链接的渠道
  • 网站建设军成/1688官网
  • Dreamweaver上网站怎么做/湖南网络营销外包
  • 武汉网站建设哪家最好/5188关键词挖掘
  • 为什么找别人做网站/太原seo哪家好
  • 如何建立公司网站是什么/客户关系管理
  • 手机做炫光图头像的网站/优化大师电脑版官方免费下载
  • appserv做网站教程/培训心得体会300字
  • 做企业网站不好混/广州中小企业seo推广运营
  • 阳春市住房规划建设局网站/提高网站排名软件
  • 自己可以做网站空间吗/企业网站的作用
  • 国家图书馆网站建设介绍/哪些行业适合做网络推广
  • 哪个浏览器不屏蔽网站/优化一下
  • 做网做网站建设/app线上推广是什么工作
  • 深圳做网站和视频宣传机构/网站制作软件
  • 政府网站集群建设/企业营销策略分析论文
  • 专业推广公司哪家好/域名seo查询
  • 孝昌县专注网站建设代理/百度产品
  • 美国做deals的网站/seo文章是什么
  • python做问卷调查的网站/新公司做网站多少钱
  • 织梦制作手机网站/简述seo的优化流程
  • 铁路建设工程网/资源优化排名网站
  • 哔哩哔哩黄页网站/企业培训体系搭建
  • 东莞做外贸网站公司/百度一下官方网页
  • 5G专网提高产业生产力
  • 鸿蒙 - 分享功能
  • 飞算JavaAI深度解析:Java开发者的智能革命
  • 二分查找算法,并分析其时间、空间复杂度
  • mapbox进阶,mapbox-gl-draw绘图插件扩展,绘制新增、编辑模式支持点、线、面的捕捉
  • FPGA学习笔记——SPI通讯协议简介