<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國際加速解決方案。 廣告
                ## 問題 Problem 你希望網絡中能有一個持久的服務,能夠與它的客戶端保持一個持續的鏈接。 You want to provide a persistent service over a network, one which maintains an on-going connection with a client. ## 方法 Solution 創建一個雙向通信的TCP服務器。 Create a bi-directional TCP server. ### 用Node.js In Node.js ~~~ net = require 'net' domain = 'localhost' port = 9001 server = net.createServer (socket) -> console.log "New connection from #{socket.remoteAddress}" socket.on 'data', (data) -> console.log "#{socket.remoteAddress} sent: #{data}" others = server.connections - 1 socket.write "You have #{others} #{others == 1 and "peer" or "peers"} on this server" console.log "Listening to #{domain}:#{port}" server.listen port, domain ~~~ ### 示例 Example Usage 使用[雙向通信的客戶端](http://island205.com/chapters/networking/bi-directional-client)。 Accessed by the?[Bi-Directional Client](http://island205.com/chapters/networking/bi-directional-client): ~~~ $ coffee bi-directional-server.coffee Listening to localhost:9001 New connection from 127.0.0.1 127.0.0.1 sent: Ping 127.0.0.1 sent: Ping 127.0.0.1 sent: Ping [...] ~~~ ## 討論 Discussion 大部分工作都在@socket.on ‘data’@這個處理器中,所有從客戶端傳過來的數據都在這里處理。一個真實的服務器會把數據傳遞給另外一個函數,對其進行處理,并產生響應供原始的處理器使用。 The bulk of the work lies in the @socket.on ‘data’@ handler, which processes all of the input from the client. A real server would likely pass the data onto another function to process it and generate any responses so that the original handler. 參看[雙向的客戶端](http://island205.com/chapters/networking/bi-directional-client),?[最簡單的客戶端](http://island205.com/chapters/networking/basic-client), 以及[最簡單的服務器](http://island205.com/chapters/networking/basic-server)這幾個菜譜。 See also the?[Bi-Directional Client](http://island205.com/chapters/networking/bi-directional-client),?[Basic Client](http://island205.com/chapters/networking/basic-client), and?[Basic Server](http://island205.com/chapters/networking/basic-server)recipes. ### 練習 Exercises * 添加自定義domain和端口的支持,可基于命令行參數,也可以使用配置文件。 * Add support for choosing the target domain and port based on command-line arguments or on a configuration file.
                  <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>

                              哎呀哎呀视频在线观看