• Node.js 中的重要API:TCP


    2019-12-16

    20:12:38

     

     

     

     

     

     

    require('http').createServer(function(req,res){
        res.writeHead(200,{'Content-Type':'text/html'});
        res.end('<h1>Hello World</h1>');
    }).listen(3000);

     

     

    /**
     * Module dependencies.
     */
    
    var net = require('net')
    
    /**
     * Create server.
     */
    
    var server = net.createServer(function (conn) {
      // handle connection
      console.log('33[90m   new connection!33[39m');
    });
    
    /**
     * Listen.
     */
    
    server.listen(3000, function () {
      console.log('33[96m   server listening on *:300033[39m');
    });

     

     

    /**
     * Module dependencies.
     */
    
    var net = require('net')
    
    /**
     * Keep track of connections.
     */
    
    var count = 0;
    
    /**
     * Create server.
     */
    
    var server = net.createServer(function (conn) {
      conn.write(
          '
     > welcome to 33[92mnode-chat33[39m!'
        + '
     > ' + count + ' other people are connected at this time.'
        + '
     > please write your name and press enter: '
      );
      count++;
      conn.on('close', function () {
        count--;
      });
    });
    
    /**
     * Listen.
     */
    
    server.listen(3000, function () {
      console.log('33[96m   server listening on *:300033[39m');
    });

     

  • 相关阅读:
    奔跑的绵羊js
    13.差分
    12.子矩阵的和
    11.前缀和
    10.高精度除法
    9.高精度乘法
    8.高精度减法
    7.高精度加法
    6.数的三次方根
    5.数的范围
  • 原文地址:https://www.cnblogs.com/JasonPeng1/p/12051350.html
Copyright © 2020-2023  润新知