zoukankan      html  css  js  c++  java
  • 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');
    });

     

  • 相关阅读:
    ArcGIS10.3.1于2015年6月发布
    jS数组
    正则表达式
    JS中prototype属性-JS原型模式
    URI, URL, and URN
    JS中的Call和apply
    北京获得2022冬奥会举办权
    JQuery.on()事件绑定
    JavaScript模块化-require.js
    SpringBoot中DataSourceAutoConfiguration注解
  • 原文地址:https://www.cnblogs.com/JasonPeng1/p/12051350.html
Copyright © 2011-2022 走看看