<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>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                ~~~ public class EchoServer { private final int port; public EchoServer(int port) { this.port = port; } /** * 1. 創建ServerBootstrap實例,并制定NioEventLoopGroup來接收和處理新的連接 * 2. 設置channel的類型為NioServerSocketChannel * 3. 設置地址端口,服務器將綁定這個地址以監聽新的請求連接 * 4. ChannelInitializer, 新的連接被接受時,一個新的子Channel被創建,ChannelInitializer會把你的 * EchoServerHandler添加到該Channel的ChannelPipeline中 * 5. EchoServerHandler將會接收到信息 * 6. 等待綁定完成,sync方法將當前Thread阻塞,一致到綁定操作完成為止 * 7. 應用程序將會阻塞等待知道服務器的Channel關閉,因為你再Channel.CloseFuture調用了sync方法 * 8. 關閉EventLoopGroup,釋放所有資源,包括被創建的線程 */ public void start() throws Exception{ EventLoopGroup group = new NioEventLoopGroup(); try { ServerBootstrap b = new ServerBootstrap(); b.group(group) .channel(NioServerSocketChannel.class) // 指定使用的Nio傳輸Channel .localAddress(new InetSocketAddress(port))//指定端口設置套接字地址 .childHandler(new ChannelInitializer<SocketChannel>() {// 添加EchoServerHandler到子Channel的ChannelPipline protected void initChannel(SocketChannel socketChannel) throws Exception { // EchoServerHandler被標記為@Shareable,所以我們可以總是使用這樣的實例 socketChannel.pipeline().addLast(new EchoServerHandler()); } }); // 6. 異步綁定服務器,調用sync方法阻塞等待知道綁定完成 ChannelFuture f = b.bind().sync(); // 7. 獲取Channel的CloseFuture,并且阻塞當前線程直到它完成 f.channel().closeFuture().sync(); } finally { // 關閉EventLoopGroup釋放所有資源 group.shutdownGracefully().sync(); } } public static void main(String[] args) { try { new EchoServer(10001).start(); }catch (Exception e){ System.out.println("服務端啟動異常"); e.printStackTrace(); } } } ~~~
                  <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>

                              哎呀哎呀视频在线观看