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

wap网站推广方法seo是干嘛的

wap网站推广方法,seo是干嘛的,做网站常用代码向右浮动怎么写,网站 会员系统 织梦4.2.4 可中断套接字 SocketChannel可以中断套接字 SocketChannel channel.open(new InetSocketAddress(host,port)); 通道(channel)并没有与之相关联的流,实际上,所拥有的read和write方法都是通过Buffer对象实现的。 如果不想处理缓冲区,…

4.2.4 可中断套接字

SocketChannel可以中断套接字

SocketChannel channel.open(new InetSocketAddress(host,port));

通道(channel)并没有与之相关联的流,实际上,所拥有的read和write方法都是通过Buffer对象实现的。

如果不想处理缓冲区,可以使用Scanner从SocketChannel中读取信息。

Scanner有一个带ReadableByteChannel参数的构造器。

var in = new Scanner(channel,StandardCharsets.UTF-8);

通过调用静态方法Channels.newOutputStream,可以将通道转换成输出流。

OutputStream outStream = Channels.newOutputStream(channel);

对比中断套接字和阻塞套接字
package 第4章网络.interruptible;import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.HeadlessException;
import java.awt.Toolkit;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;public class InterruptibleSocketTest {public static void main(String[] args) {var frame = new InterruptibleSocketFrame();frame.setTitle("InterruptibleSocketTest");
//        frame.setSize(400, 400);//初始打开为屏幕中央Toolkit toolkit = Toolkit.getDefaultToolkit();Dimension screenSize = toolkit.getScreenSize();int screenWidth = (int) screenSize.getWidth();int screenHeight = (int) screenSize.getHeight();//计算窗口位置int x = (screenWidth - frame.getWidth())/2;int y = (screenHeight - frame.getHeight())/2;frame.setLocation(x, y);frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);frame.setVisible(true);}}
class InterruptibleSocketFrame extends JFrame {private Scanner in;private JButton interruptibleButton;private JButton blockingButton;private JButton cancelButton;private JTextArea messages;private TestServer server;private Thread connectThread;public InterruptibleSocketFrame() throws HeadlessException {var northPanel = new JPanel();add(northPanel,BorderLayout.NORTH);final int TEXT_ROWS = 20;final int TEXT_COLUMNS = 60;messages = new JTextArea(TEXT_ROWS, TEXT_COLUMNS);add(new JScrollPane(messages));interruptibleButton = new JButton("可中断");blockingButton = new JButton("阻塞中");northPanel.add(interruptibleButton);northPanel.add(blockingButton);interruptibleButton.addActionListener(e -> {interruptibleButton.setEnabled(false);blockingButton.setEnabled(false);cancelButton.setEnabled(true);connectThread = new Thread(() -> {try {connectInterruptibly();} catch (IOException e1) {messages.append("\nInterruptibleSocketTest.connectInterruptibly: "+e);}});connectThread.start();});blockingButton.addActionListener(e -> {interruptibleButton.setEnabled(false);blockingButton.setEnabled(false);cancelButton.setEnabled(true);connectThread = new Thread(() -> {try {connectBlocking();} catch (IOException e1) {messages.append("\nInterruptibleSocketTest.connectBlocking: "+e);}});connectThread.start();});cancelButton = new JButton("取消");cancelButton.setEnabled(false);northPanel.add(cancelButton);cancelButton.addActionListener(e -> {connectThread.interrupt();cancelButton.setEnabled(false);});server = new TestServer();new Thread(server).start();pack();}//连接测试服务器,用可中断IOpublic void connectInterruptibly() throws IOException {messages.append("可中断:\n");try (SocketChannel channel = SocketChannel.open(new InetSocketAddress("localhost",8189))){in = new Scanner(channel,StandardCharsets.UTF_8);while(!Thread.currentThread().isInterrupted()) {messages.append("读取 ");if(in.hasNextLine()) {String line = in.nextLine();messages.append(line);messages.append("\n");}}} finally {EventQueue.invokeLater(() -> {messages.append("管道关闭\n");interruptibleButton.setEnabled(true);blockingButton.setEnabled(true);});}}//连接测试服务器,用阻塞IOpublic void connectBlocking() throws UnknownHostException, IOException {messages.append("阻塞中:\n");try (var sock = new Socket("localhost",8189)){in = new Scanner(sock.getInputStream(),StandardCharsets.UTF_8);while(!Thread.currentThread().isInterrupted()) {messages.append("读取 ");if (in.hasNextLine()) {String line = in.nextLine();messages.append(line);messages.append("\n");}}} finally {EventQueue.invokeLater(() -> {messages.append("套接字关闭\n");interruptibleButton.setEnabled(true);blockingButton.setEnabled(true);});}}class TestServer implements Runnable {@Overridepublic void run() {try(var s = new ServerSocket(8189)){while (true) {Socket incoming = s.accept();Runnable r = new TestServerHandler(incoming);new Thread(r).start();}} catch (IOException e) {messages.append("\nTestServer.run: "+e);}}}class TestServerHandler implements Runnable{private Socket incoming;private int counter;public TestServerHandler(Socket incoming) {super();this.incoming = incoming;}@Overridepublic void run() {OutputStream outStream;try {try {outStream = incoming.getOutputStream();var out = new PrintWriter(new OutputStreamWriter(outStream, StandardCharsets.UTF_8),true);while(counter < 100) {counter++;if(counter<=10) out.println(counter);Thread.sleep(100);}}finally {incoming.close();messages.append("关闭服务\n");}} catch (Exception e) {messages.append("\nTestServerHandler.run:"+e);}}}
}

http://www.hkea.cn/news/238523/

相关文章:

  • 阿里巴巴网站国际站建设seo托管服务
  • 企业网站优化之如何做需求分析网奇seo赚钱培训
  • 施工企业会计制度收入确认规定百度自然排名优化
  • 校园网站建设意义网络营销的特点有哪些
  • 内江做网站哪里便宜google搜索关键词热度
  • 福建省建设银行招聘网站网络推广员压力大吗
  • 动态网站订单怎么做搜索引擎优化营销
  • html5行业网站最近有哪些新闻
  • 做网站业务的怎么寻找客户在哪里打广告效果最好
  • 广东深圳seo服务内容
  • 做网站怎么备案网络服务有限公司
  • 网站主页特效欣赏百度官网下载电脑版
  • php mysql开发网站开发任何小说都能搜到的软件
  • the7 wordpress主题宁波seo外包费用
  • 云南建筑培训网seo刷点击软件
  • 男女做暖网站h5页面制作平台
  • 可以做puzzle的网站百度关键词排名提升工具
  • 竞网网站建设南宁网站seo大概多少钱
  • 114黄页信息网宝鸡seo培训
  • 东南亚做棋牌网站挖掘爱站网
  • 中国工程建设招标网官方网站谷歌查询关键词的工具叫什么
  • wordpress管理员密码忘记成都seo招聘
  • 武汉企业建站系统模板下载官方正版百度
  • 上海做网站国际财经新闻
  • 用废旧盒子做家用物品网站seo排名工具
  • 企业铭做网站域名解析在线查询
  • 怎么注册自己的小程序网站优化分析
  • 荆州网站建设流程网站设计培训
  • 网站支付怎么做的seo职业技能培训班
  • 做csgo直播网站上海知名网站制作公司