<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                服務端 ~~~ import java.io.*; 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.util.Iterator; public class Server { public static void main(String[] args) throws IOException { // 服務端通道 final ServerSocketChannel ssChannel = ServerSocketChannel.open(); // 配置阻塞為false ssChannel.configureBlocking(false); // 綁定端口 ssChannel.bind(new InetSocketAddress(9999)); final Selector selector = Selector.open(); // 將通道都注冊到選擇器上,并且開始監聽事件 ssChannel.register(selector, SelectionKey.OP_ACCEPT); // 使用Selector選擇器已經準備好的事件 while (selector.select()>0){ // 獲取選擇器中所有注冊的通道已經就緒好的事件 final Iterator<SelectionKey> iterator = selector .selectedKeys() .iterator(); while (iterator.hasNext()){ final SelectionKey selectionKey = iterator.next(); if (selectionKey.isAcceptable()){ final SocketChannel accept = ssChannel.accept(); accept.configureBlocking(false); // 讀 accept.register(selector,SelectionKey.OP_READ); } // 讀 if (selectionKey.isReadable()){ final SocketChannel channel =(SocketChannel) selectionKey.channel(); final ByteBuffer allocate = ByteBuffer.allocate(1024); int len=0; while ((len=channel.read(allocate))>0){ allocate.flip(); System.out.println(new String(allocate.array(),0,len)); allocate.clear(); } } iterator.remove(); } } } } ~~~ 客戶端 ~~~ import java.io.*; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; import java.nio.charset.StandardCharsets; import java.util.Date; import java.util.Scanner; public class Client { public static void main(String[] args) throws IOException { final SocketChannel open = SocketChannel.open(new InetSocketAddress(9999)); open.configureBlocking(false); final ByteBuffer allocate = ByteBuffer.allocate(1024); final Scanner scanner = new Scanner(System.in); while (true){ System.out.println("請說話:"); final String line = scanner.nextLine(); allocate.put(line.getBytes()); allocate.flip(); open.write(allocate); allocate.clear(); } } } ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看