• nodejs net模块实现socket



    var
    net = require('net'); var client = net.connect({port: 8080}, function() { console.log('连接到服务器!'); }); client.on('data', function(data) { console.log(data.toString()); client.end(); }); client.on('end', function() { console.log('断开与服务器的连接'); });

    客户端代码

    var net = require('net');
    var server = net.createServer(function(connection) { 
       console.log('client connected');
       connection.on('end', function() {
          console.log('客户端关闭连接');
       });
       connection.write('Hello World!
    ');
       connection.pipe(connection);
    });
    server.listen(8080, function() { 
      console.log('server is listening');
    });

    服务器端代码

    实现socket

  • 相关阅读:
    canvas之碎碎念
    canvas之动态时钟
    属性小问题
    readonly and disabled
    table
    地图热区
    子块元素在父块元素中居中
    Ajax与JS
    前端测试
    html5/css3
  • 原文地址:https://www.cnblogs.com/liuwenbohhh/p/5004598.html
Copyright © 2020-2023  润新知