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

网站建设中的功能推广普通话ppt课件免费

网站建设中的功能,推广普通话ppt课件免费,微商城网站建设教程,徐汇网站制作设计一、Netty服务端开发在开始使用 Netty 开发 TimeServer 之前#xff0c;先回顾一下使用 NIO 进行服务端开发的步骤。(1)创建ServerSocketChannel#xff0c;配置它为非阻塞模式;(2)绑定监听#xff0c;配置TCP 参数#xff0c;例如 backlog 大小;(3)创建一个独立的I/O线程先回顾一下使用 NIO 进行服务端开发的步骤。(1)创建ServerSocketChannel配置它为非阻塞模式;(2)绑定监听配置TCP 参数例如 backlog 大小;(3)创建一个独立的I/O线程用于轮询多路复用器 Selector;(4)创建 Selector将之前创建的 ServerSocketChannel 注册到 Selector 上监听SelectionKey.ACCEPT;(5)启动I/0线程在循环体中执行 Selectorselect0)方法轮询就绪的 Channel;(6)当轮询到了处于就绪状态的 Channel 时需要对其进行判断如果是OP ACCEPT状态说明是新的客户端接入则调用 ServerSocketChannel.accept()方法接受新的客户端:(7)设置新接入的客户端链路 SocketChannel 为非阻塞模式,配置其他的一些TCP 参数(8)将SocketChannel注册到 Selector监听 OP READ 操作位;(9)如果轮询的Channel为OP READ则说明 SocketChannel 中有新的就绪的数据包需要读取则构造ByteBuffer 对象读取数据包;(10)如果轮询的Channel为OP WRITE说明还有数据没有发送完成需要继续发送。import io.netty.bootstrap.ServerBootstrap;import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufAllocator; import io.netty.buffer.CompositeByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.*; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioServerSocketChannel; import io.netty.handler.codec.string.StringDecoder; import io.netty.handler.timeout.IdleStateHandler; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Value;public class nettyServer {Logger logger LoggerFactory.getLogger(nettyServer.class);Value(${netty.port})int port;PostConstructpublic void bind() {EventLoopGroup bossrGroup new NioEventLoopGroup();//接收客户端传过来的请求EventLoopGroup wokerGroup new NioEventLoopGroup();//接收到请求后将后续操作try {ServerBootstrap b new ServerBootstrap();b.group(bossrGroup, wokerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 1024)//.childOption(ChannelOption.SO_KEEPALIVE, true).childHandler(new ChannelInitializerSocketChannel() {Overrideprotected void initChannel(SocketChannel ch) throws Exception {ch.pipeline().addLast(new serverHandlerAdapter());ch.pipeline().addLast(new StringDecoder());ch.pipeline().addLast(new HeartbeatHandler());ch.pipeline().addLast(new IdleStateHandler(10, 1, 1));}});ChannelFuture f b.bind(port).sync();} catch (Exception e) {}}import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter;public class serverHandlerAdapter extends ChannelInboundHandlerAdapter {Overridepublic void channelActive(ChannelHandlerContext ctx) throws Exception {super.channelActive(ctx);}Overridepublic void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {super.channelRead(ctx, msg);}Overridepublic void channelReadComplete(ChannelHandlerContext ctx) throws Exception {super.channelReadComplete(ctx);}Overridepublic void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {super.exceptionCaught(ctx, cause);}二、Netty客户端开发import io.netty.bootstrap.Bootstrap; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelInitializer; import io.netty.channel.EventLoopGroup; import io.netty.channel.nio.NioEventLoopGroup; import io.netty.channel.socket.SocketChannel; import io.netty.channel.socket.nio.NioSocketChannel;public class nettyClient {clientHandlerAdapter clientHandlerAdapter new clientHandlerAdapter();public void conect(String ip, int port) {EventLoopGroup group new NioEventLoopGroup();try {Bootstrap b new Bootstrap();b.group(group).channel(NioSocketChannel.class).remoteAddress(, port).handler(new ChannelInitializerSocketChannel() {Overrideprotected void initChannel(SocketChannel ch) throws Exception {ch.pipeline().addLast(clientHandlerAdapter);}});b.bind(ip, port).sync();} catch (Exception e) {}}public boolean sendFile() {return clientHandlerAdapter.sendFile();}}我们从 connect 方法讲起在第 13 行首先创建客户端处理 I/0 读写的 NioEventLoopGroup 线程组然后继续创建客户端辅助启动类 Bootstrap随后需要对其进行配置。与服务端不同的是它的 Channel 需要设置为 NioSocketChannel然后为其添加 handler此处为了简单直接创建匿名内部类实现 initChannel 方法其作用是当创建 NioSocketChannel成功之后在初始化它的时候将它的 ChannelHandler 设置到 ChannelPipeline 中用于处理网络I/O事件。客户端启动辅助类设置完成之后调用 connect 方法发起异步连接然后调用同步方法等待连接成功。最后当客户端连接关闭之后客户端主函数退出在退出之前释放 NIO 线程组的资源。下面我们继续看下TimeClientHandler 的代码如何实现
http://www.dnsts.com.cn/news/235970.html

相关文章:

  • 推广型网站建设模板安装wordpress之前需要先安装包
  • 聊天室网站模板量体定制
  • 天津市住房与城乡建设部网站中国建设银行购物网站
  • 私募基金网站建设要求wordpress手机投放广告
  • 重庆网站seo技术科技类网站风格
  • 济南网站建设哪家强 资海h5模板网站模板
  • 财政局门户网站建设方案php购物网站开发实例源码
  • 丰台网站制作浩森宇特网站后缀cc
  • 企业网站建设费用 珠海品牌建设和品牌打造方法
  • 福田网站的建设沈阳做网站公司
  • 深圳松岗网站建设做网站的怎么认证微博
  • 企业网站建设之域名篇教学网站建设 效益
  • 一台vps主机可以建设多少个网站企业采购平台排名
  • 企业建站公司报价做网站的过程
  • 个人主页类网站开发背景响应式网站 768 320
  • 网站开发包括后台 前台个人自我介绍网页
  • 一个网站放两个vps我们不是做网站的
  • 中国建设厅官方网站网站建设职业去哪里上班
  • 网站制作与网页制作广州seo培训
  • 网站平台需要做无形资产吗 怎么做微信公众管理平台
  • 山东电力建设河北分公司网站手机做网站对比路由器做网站
  • seo网站优化课程怎样凡科建设网站
  • 做一个同城便民信息网站怎么做门户网站做公众号的好处
  • 做调查问卷的网站知乎网站视频嵌入代码
  • 重庆网站推广联系方式莱芜招聘
  • 网站建设伍金手指下拉8开化网站建设公司
  • 佛山企业网站建设策划苏州有什么好玩的游乐园
  • 视频网站logo怎么做的电子商务网站开发环境
  • 免费模板素材网站有哪些网站备案地址
  • 深圳龙岗淘宝网站建设公司有哪些wordpress首饰商城系统