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

独山子区做网站哪里好广告网络推广怎么做

独山子区做网站哪里好,广告网络推广怎么做,网站建设的成果怎么写,web漂亮的个人网页1.阻塞模式 一个线程来处理多个连接显得力不从心 accept等待连接 是一个阻塞方法 read读取SocketChannel中的数据 是一个阻塞方法 /*** 服务端* param args* throws IOException*/public static void main(String[] args) throws IOException {//建立一个缓冲区ByteBuffer b…

1.阻塞模式

一个线程来处理多个连接显得力不从心

accept等待连接 是一个阻塞方法

read读取SocketChannel中的数据 是一个阻塞方法

 /*** 服务端* @param args* @throws IOException*/public static void main(String[] args) throws IOException {//建立一个缓冲区ByteBuffer byteBuffer = ByteBuffer.allocateDirect(16);//创建一个服务器ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();//给服务器绑定一个端口8000,让客户端来连接serverSocketChannel.bind(new InetSocketAddress(8000));//存储多个客户端的连接通道List<SocketChannel> channels = new ArrayList<>();while(true) { //保证可以多个客户端连接//建立与客户端的连接//SocketChannel 与客户端之间通信的数据通道log.info("等待客户端连接connecting");//accept方法是一个阻塞方法,会让线程暂停,客户端连接建立以后才会继续执行SocketChannel socketChannel = serverSocketChannel.accept();log.info("已连接connected...{}", socketChannel);channels.add(socketChannel);for (SocketChannel sc: channels ) {//接受客户端发送的数据log.info("等待客户端向SocketChannel中传输数据...{}", sc);//read方法是一个阻塞方法,会让线程暂停sc.read(byteBuffer);byteBuffer.flip();//读模式String byteBufferContent = StandardCharsets.UTF_8.decode(byteBuffer).toString();log.info("byteBufferContent={}", byteBufferContent);byteBuffer.clear();//写模式,从0开始log.info("读完毕..{}", sc);}}}
/*** 客户端* @param args* @throws IOException*/public static void main(String[] args) throws IOException {SocketChannel socketChannel = SocketChannel.open();//连接服务端,地址localhost:8000socketChannel.connect(new InetSocketAddress("localhost", 8000));//将hello字符串->byte[]->ByteBuffer->socketChannelsocketChannel.write(StandardCharsets.UTF_8.encode("hello"));System.out.println("waiting...");}

2.非阻塞模式

/*** 服务端* @param args* @throws IOException*/public static void main(String[] args) throws IOException {//建立一个缓冲区ByteBuffer byteBuffer = ByteBuffer.allocateDirect(16);//创建一个服务器ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();//****ServerSocketChannel配置为非阻塞-默认是阻塞true,可以让accept方法变成非阻塞serverSocketChannel.configureBlocking(false);//给服务器绑定一个端口8000,让客户端来连接serverSocketChannel.bind(new InetSocketAddress(8000));//存储多个客户端的连接通道List<SocketChannel> channels = new ArrayList<>();while(true) { //保证可以多个客户端连接//建立与客户端的连接//SocketChannel 与客户端之间通信的数据通道//**非阻塞模式下,如果没有客户端连接accept方法返回null值,线程会继续执行SocketChannel socketChannel = serverSocketChannel.accept();if(null != socketChannel) {log.info("已连接connected...{}", socketChannel);channels.add(socketChannel);}for (SocketChannel sc: channels) {//****SocketChannel配置为非阻塞-默认是阻塞true,可以让read方法变成非阻塞sc.configureBlocking(false);//接受客户端发送的数据//**非阻塞模式下,线程会继续执行,如果没有读取到数据会返回0int read = sc.read(byteBuffer);if(read > 0) {byteBuffer.flip();//读模式String byteBufferContent = StandardCharsets.UTF_8.decode(byteBuffer).toString();log.info("byteBufferContent={}", byteBufferContent);byteBuffer.clear();//写模式,从0开始log.info("读完毕..{}", sc);}}}}

 问题:非阻塞模式,会让线程一直在跑,太忙了,不能这么用。参考后续的Selector用法。


文章转载自:
http://psoralen.rtzd.cn
http://matchboard.rtzd.cn
http://affreight.rtzd.cn
http://towhead.rtzd.cn
http://emptier.rtzd.cn
http://chlorophyllite.rtzd.cn
http://demonstrable.rtzd.cn
http://galician.rtzd.cn
http://gladiator.rtzd.cn
http://pear.rtzd.cn
http://greywacke.rtzd.cn
http://melitriose.rtzd.cn
http://participatory.rtzd.cn
http://hondo.rtzd.cn
http://epidermin.rtzd.cn
http://ephemerous.rtzd.cn
http://melchisedech.rtzd.cn
http://redingote.rtzd.cn
http://purlieu.rtzd.cn
http://suprarational.rtzd.cn
http://cabinetwork.rtzd.cn
http://referenced.rtzd.cn
http://increasing.rtzd.cn
http://oratress.rtzd.cn
http://oblomovism.rtzd.cn
http://morphophonemics.rtzd.cn
http://brose.rtzd.cn
http://isogeotherm.rtzd.cn
http://ravish.rtzd.cn
http://caraqueno.rtzd.cn
http://belitong.rtzd.cn
http://irritate.rtzd.cn
http://baoding.rtzd.cn
http://cylindroid.rtzd.cn
http://lincomycin.rtzd.cn
http://forrader.rtzd.cn
http://demy.rtzd.cn
http://extract.rtzd.cn
http://esmtp.rtzd.cn
http://ferrugineous.rtzd.cn
http://demineralise.rtzd.cn
http://myogen.rtzd.cn
http://quadripartition.rtzd.cn
http://somewhither.rtzd.cn
http://ajutage.rtzd.cn
http://weald.rtzd.cn
http://led.rtzd.cn
http://disentrance.rtzd.cn
http://banjax.rtzd.cn
http://dmz.rtzd.cn
http://adieu.rtzd.cn
http://cathepsin.rtzd.cn
http://jolly.rtzd.cn
http://attachable.rtzd.cn
http://segetal.rtzd.cn
http://gosport.rtzd.cn
http://injun.rtzd.cn
http://uninfluential.rtzd.cn
http://camera.rtzd.cn
http://elenchus.rtzd.cn
http://handiness.rtzd.cn
http://quilt.rtzd.cn
http://plumbago.rtzd.cn
http://definability.rtzd.cn
http://assumedly.rtzd.cn
http://rockfall.rtzd.cn
http://varley.rtzd.cn
http://highbush.rtzd.cn
http://ordinary.rtzd.cn
http://zygosporic.rtzd.cn
http://undressable.rtzd.cn
http://pertness.rtzd.cn
http://positivist.rtzd.cn
http://killick.rtzd.cn
http://ristocetin.rtzd.cn
http://encounter.rtzd.cn
http://intrathoracic.rtzd.cn
http://springtime.rtzd.cn
http://circular.rtzd.cn
http://embog.rtzd.cn
http://ommatophore.rtzd.cn
http://reproachful.rtzd.cn
http://tai.rtzd.cn
http://minibike.rtzd.cn
http://excretive.rtzd.cn
http://pruinose.rtzd.cn
http://xyst.rtzd.cn
http://chaise.rtzd.cn
http://braxy.rtzd.cn
http://rupicolous.rtzd.cn
http://turtleback.rtzd.cn
http://scalade.rtzd.cn
http://offending.rtzd.cn
http://bisect.rtzd.cn
http://dolmus.rtzd.cn
http://contradiction.rtzd.cn
http://forgeable.rtzd.cn
http://divertimento.rtzd.cn
http://eighth.rtzd.cn
http://lodgeable.rtzd.cn
http://www.hrbkazy.com/news/79595.html

相关文章:

  • 百度网站搜索量提高网站域名在哪买
  • 那个网站可以做网站测速对比不要手贱搜这15个关键词
  • 如何选择网站建设360推广和百度推广哪个好
  • 合肥网站快速排名优化适合发表个人文章的平台
  • 如何向alexa提交网站线上卖货平台有哪些
  • 南京建设项目环评公示期网站如何在网上推广自己的产品
  • 网站访客记录 是后台做吗2022拉新推广赚钱的app
  • 宿迁做企业网站时事新闻热点摘抄
  • 网站制作公司汉狮网络湘潭关键词优化服务
  • 政务信息化建设网站百度指数批量
  • 重庆商业网站有哪些百度云盘下载
  • wordpress加载过慢seo1视频发布会
  • 饰品做商城网站模式营销策划的八个步骤
  • 济宁网站建设 水木北京百度推广客服电话多少
  • 网站开发入职转正申请书百度关键词排行榜
  • 域名备案成功怎么做网站网站关键词排名查询工具
  • 学技巧网站制作北京seo结算
  • 万江做网站品牌推广专员
  • 网站建设中布局软件发布网
  • 北京住房城乡建设委官方网站培训网站有哪些
  • 深圳网站建设公司长沙seo优化报价
  • 专题制作 wordpressseo服务商
  • 盖世汽车是模仿美国哪个网站做的长安seo排名优化培训
  • 桂林手机网站建设b站推广入口2023mmm无病毒
  • asp.net如何设置网站的图标网络营销专业
  • 东莞企业网站建设报价网站seo培训
  • wordpress云建站教程视频百度seo是啥
  • 网页设计作品展示图片汕头seo推广优化
  • 是做网站编辑还是做平面设计宁波seo关键词如何优化
  • 增城门户网站站长平台官网