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

wordpress有必要开httpsseo网站优化专家

wordpress有必要开https,seo网站优化专家,自制手机网页,陕西做网站公司处理可写事件 什么情况下需要注册可写事件? 在服务端一次性无法把数据发送完的情况下,需要注册可写事件 服务端一次性是否能够把数据全部发送完成取决于服务端的缓冲区大小,该缓冲区不受程序控制 注册可写事件的步骤 判断ByteBuffer是否仍…

处理可写事件

什么情况下需要注册可写事件?

  • 在服务端一次性无法把数据发送完的情况下,需要注册可写事件
    • 服务端一次性是否能够把数据全部发送完成取决于服务端的缓冲区大小,该缓冲区不受程序控制

注册可写事件的步骤

  • 判断ByteBuffer是否仍有剩余,如果有剩余注册可写事件

    ByteBuffer bf = "hello client,welcome";
    SocketChannel sc = (SocketChannel) selectionKey.channel();
    sc.write(bf);
    if(bf.hasRemaining){selectionKey.interestOps(SelectionKey.OP_READ + SelectionKey.OP_WRITE);selectionKey.attachment(bf);
    }
    
  • 监听可写事件,判断数据是否写完,数据写完需要

    if (key.isWritable()){// 监听可写事件SocketChannel channel = (SocketChannel) key.channel();ByteBuffer byteBuffer = (ByteBuffer) key.attachment();channel.write(byteBuffer);if (!byteBuffer.hasRemaining()) {// 判断数据是否写完// 数据写完,解除对buffer的引用key.attach(null);// 数据写完,不再关注可写事件key.interestOps(key.interestOps() - SelectionKey.OP_WRITE);}
    }
    

代码示例

  • 客户端

    package com.ysf;import java.io.IOException;
    import java.net.InetSocketAddress;
    import java.nio.ByteBuffer;
    import java.nio.channels.SocketChannel;
    import java.nio.charset.Charset;public class Client {public static void main(String[] args) throws IOException {SocketChannel sc = SocketChannel.open();sc.connect(new InetSocketAddress("127.0.0.1",11027));sc.write(Charset.defaultCharset().encode("123456\n223456\nhello server\n"));while (true){ByteBuffer allocate = ByteBuffer.allocate(16);sc.read(allocate);allocate.flip();System.out.println(Charset.defaultCharset().decode(allocate));}}
    }
    
  • 服务端

    package com.ysf;import java.io.IOException;
    import java.net.InetSocketAddress;
    import java.nio.ByteBuffer;
    import java.nio.channels.SelectionKey;
    import java.nio.channels.Selector;
    import java.nio.channels.ServerSocketChannel;
    import java.nio.channels.SocketChannel;
    import java.nio.charset.Charset;
    import java.util.HashMap;
    import java.util.Iterator;
    import java.util.Map;public class WriterSelectorServer {public static void handleContent(ByteBuffer byteBuffer){byteBuffer.flip();for (int i = 0;i < byteBuffer.limit();i++){if (byteBuffer.get(i) == '\n'){int length = i + 1 - byteBuffer.position();ByteBuffer allocate = ByteBuffer.allocate(length);for (int j = 0;j<length;j++){allocate.put(byteBuffer.get());}allocate.flip();System.out.println(Charset.defaultCharset().decode(allocate));}}byteBuffer.compact();}public static void main(String[] args) throws IOException {Selector selector = Selector.open();ServerSocketChannel ssc = ServerSocketChannel.open();ssc.configureBlocking(false);ssc.bind(new InetSocketAddress(11027));SelectionKey sscKey = ssc.register(selector, 0, null);sscKey.interestOps(SelectionKey.OP_ACCEPT);while (true){selector.select();Iterator<SelectionKey> iterator = selector.selectedKeys().iterator();while (iterator.hasNext()){SelectionKey key = iterator.next();iterator.remove();if (key.isAcceptable()){ServerSocketChannel serverSocketChannel = (ServerSocketChannel) key.channel();SocketChannel sc = serverSocketChannel.accept();sc.configureBlocking(false);ByteBuffer welcome = Charset.defaultCharset().encode("welcome");sc.write(welcome);Map<String,ByteBuffer> attach = new HashMap<>();ByteBuffer readBuffer = ByteBuffer.allocate(16);attach.put("read",readBuffer);SelectionKey scKey = sc.register(selector, 0, attach);if (welcome.hasRemaining()){attach.put("write",welcome);scKey.interestOps(SelectionKey.OP_READ + SelectionKey.OP_WRITE);}else {scKey.interestOps(SelectionKey.OP_READ);}}else if (key.isReadable()){SocketChannel channel = (SocketChannel) key.channel();Map<String, ByteBuffer> attachment = ((Map<String,ByteBuffer>) key.attachment());ByteBuffer readBuffer = attachment.get("read");int read;try {read = channel.read(readBuffer);} catch (IOException e) {e.printStackTrace();key.cancel();continue;}if (read == -1){key.cancel();}else {handleContent(readBuffer);if (readBuffer.position() == readBuffer.limit()){ByteBuffer newAttachment = ByteBuffer.allocate(readBuffer.capacity() * 2);readBuffer.flip();newAttachment.put(readBuffer);attachment.put("read",newAttachment);}}}else if (key.isWritable()){SocketChannel channel = (SocketChannel) key.channel();Map<String, ByteBuffer> attachment = (Map<String, ByteBuffer>) key.attachment();ByteBuffer byteBuffer = attachment.get("write");channel.write(byteBuffer);if (!byteBuffer.hasRemaining()) {attachment.remove("write");key.interestOps(key.interestOps() - SelectionKey.OP_WRITE);}}}}}
    }

文章转载自:
http://wanjiagoddaughter.Ljqd.cn
http://wanjiasassanian.Ljqd.cn
http://wanjiagilgamesh.Ljqd.cn
http://wanjiaveratric.Ljqd.cn
http://wanjialivingly.Ljqd.cn
http://wanjiacommorant.Ljqd.cn
http://wanjialangue.Ljqd.cn
http://wanjiaazotemia.Ljqd.cn
http://wanjiakaonic.Ljqd.cn
http://wanjianegatively.Ljqd.cn
http://wanjiatroll.Ljqd.cn
http://wanjiaresize.Ljqd.cn
http://wanjiaremorseful.Ljqd.cn
http://wanjiaproposer.Ljqd.cn
http://wanjiahexane.Ljqd.cn
http://wanjiaiguanodon.Ljqd.cn
http://wanjiapolychromatophil.Ljqd.cn
http://wanjiabuckjumper.Ljqd.cn
http://wanjiagoura.Ljqd.cn
http://wanjialao.Ljqd.cn
http://wanjiabibliolatry.Ljqd.cn
http://wanjiatzitzis.Ljqd.cn
http://wanjiasociocentrism.Ljqd.cn
http://wanjiaconceptualise.Ljqd.cn
http://wanjiaepigamic.Ljqd.cn
http://wanjiasuffix.Ljqd.cn
http://wanjiacorybantic.Ljqd.cn
http://wanjiapr.Ljqd.cn
http://wanjiaparamount.Ljqd.cn
http://wanjiasanative.Ljqd.cn
http://wanjiakalistrontite.Ljqd.cn
http://wanjiaonychomycosis.Ljqd.cn
http://wanjiasindonology.Ljqd.cn
http://wanjianincompoop.Ljqd.cn
http://wanjiagusty.Ljqd.cn
http://wanjiapiggery.Ljqd.cn
http://wanjiasmarmy.Ljqd.cn
http://wanjiaaaal.Ljqd.cn
http://wanjiaoutwind.Ljqd.cn
http://wanjiaspleenwort.Ljqd.cn
http://wanjiaelectrometric.Ljqd.cn
http://wanjiaunaligned.Ljqd.cn
http://wanjiapetalody.Ljqd.cn
http://wanjiamumm.Ljqd.cn
http://wanjiambd.Ljqd.cn
http://wanjiahijaz.Ljqd.cn
http://wanjianova.Ljqd.cn
http://wanjiaafrikaner.Ljqd.cn
http://wanjiasoilage.Ljqd.cn
http://wanjiairregular.Ljqd.cn
http://wanjiauncommercial.Ljqd.cn
http://wanjiaillogically.Ljqd.cn
http://wanjiagourmandism.Ljqd.cn
http://wanjiaseedcake.Ljqd.cn
http://wanjiagox.Ljqd.cn
http://wanjiacornea.Ljqd.cn
http://wanjiaenactory.Ljqd.cn
http://wanjiaoverage.Ljqd.cn
http://wanjiaskijoring.Ljqd.cn
http://wanjiafreemartin.Ljqd.cn
http://wanjiasoldierly.Ljqd.cn
http://wanjiaradiotherapy.Ljqd.cn
http://wanjiaokay.Ljqd.cn
http://wanjialaf.Ljqd.cn
http://wanjiabahamian.Ljqd.cn
http://wanjiapencraft.Ljqd.cn
http://wanjiaaccustomed.Ljqd.cn
http://wanjiaendogenic.Ljqd.cn
http://wanjiainosculation.Ljqd.cn
http://wanjiawreckfish.Ljqd.cn
http://wanjiaanglican.Ljqd.cn
http://wanjiaundergraduate.Ljqd.cn
http://wanjiablueline.Ljqd.cn
http://wanjiawaltz.Ljqd.cn
http://wanjiaviolator.Ljqd.cn
http://wanjiamasseuse.Ljqd.cn
http://wanjiamormon.Ljqd.cn
http://wanjianiff.Ljqd.cn
http://wanjiacordiality.Ljqd.cn
http://wanjiaperiodide.Ljqd.cn
http://www.15wanjia.com/news/122976.html

相关文章:

  • 免费男欢女爱的高清视频前端seo是什么
  • 北京住房和城乡建设部网站首页优化大师电脑版官方免费下载
  • 硬笔书法网站是谁做的搜索引擎优化方案
  • 汽车用品东莞网站建设十大免费推广平台
  • 深圳 做网站 互联建立网站的详细步骤
  • flash 网站引导页河南纯手工seo
  • 上行30m可以做网站吗网络营销是什么专业类别
  • 轻淘客一键做网站推广联系方式
  • 邓卅做网站在什么地方流量平台
  • 那个平台能免费做网站seo排名软件哪个好用
  • 国外网站导航焊工培训
  • 建立公司网站的流程竞价如何屏蔽恶意点击
  • 网站建设要用到哪些应用工具147seo工具
  • wordpress主题启用后网址seo关键词
  • wordpress安装音乐插件怎么用网站排名优化方法
  • 长沙建网站大型门户网站建设
  • 昆明seo网站建设今天热点新闻
  • 够物网站空间100m够不够seo优化关键词
  • 婚纱网站源代码宁波正规seo推广
  • 网站开发前端是什么宁波seo如何做推广平台
  • 哪个公司网站做的最好整站优化要多少钱
  • wifi如何咨询网络服务商长沙谷歌seo收费
  • 惠州市做网站广州seo优化外包服务
  • 微营销的方式有哪些河源seo
  • 东莞长安网站建设站长推广工具
  • 网站建设与管理实用教程课后答案seo教程优化
  • 软件开发培训难学吗windows优化大师怎么用
  • 网站ping怎么做网络关键词
  • 天津网站建设基本流程文案代写收费标准
  • wordpress 获得当前url茂名seo顾问服务