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

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## 問題 你希望網絡中能有一個持久的服務,能夠與它的客戶端保持一個持續的鏈接。 ## 方法 創建一個雙向的TCP客戶端。 ### 使用Node.js來實現 ~~~ net = require 'net' domain = 'localhost' port = 9001 ping = (socket, delay) -> console.log "Pinging server" socket.write "Ping" nextPing = -> ping(socket, delay) setTimeout nextPing, delay connection = net.createConnection port, domain connection.on 'connect', () -> console.log "Opened connection to #{domain}:#{port}" ping connection, 2000 connection.on 'data', (data) -> console.log "Received: #{data}" connection.on 'end', (data) -> console.log "Connection closed" process.exit() ~~~ ### 示例 訪問[雙向服務器](http://island205.com/chapters/networking/bi-directional-server): ~~~ $ coffee bi-directional-client.coffee Opened connection to localhost:9001 Pinging server Received: You have 0 peers on this server Pinging server Received: You have 0 peers on this server Pinging server Received: You have 1 peer on this server [...] Connection closed ~~~ ## 討論 這個特例開始與服務器交互,并在@connection.on ‘connect’@處理器中與服務器交流。然而,在一個真實的客戶端中,絕大部分的工作都依賴與@connection.on ‘data’@處理器,它能夠處理服務端的輸出。重復的@ping@函數,僅僅只是為了表示與服務端的交互是持續性的,實際上在真實的客戶端中可以把它移除。 參看[雙向的服務器](http://island205.com/chapters/networking/bi-directional-server),?[最基本的客戶端](http://island205.com/chapters/networking/basic-client)這兩個菜譜。 ### 練習 * 添加自定義domain和端口的支持,可基于命令行參數,也可以使用配置文件。
                  <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>

                              哎呀哎呀视频在线观看