Node.js中的Net模块

来源:互联网 发布:怎样下载cad软件 编辑:程序博客网 时间:2024/06/06 07:07

简介

Net模块用于底层的网络通信


函数

net.createServer([options][, connectionListener])

创建一个新的 TCP 服务器

options 是一个包含下列缺省值的对象:

{ allowHalfOpen: false}


var net = require('net');var server = net.createServer(function(c) { // 'connection' 监听器  console.log('服务器已连接');  c.on('end', function() {    console.log('服务器已断开');  });  c.write('hello\r\n');  c.pipe(c);});server.listen(8124, function() { // 'listening' 监听器  console.log('服务器已绑定');});

net.connect(options[, connectListener])

net.createConnection(options[, connectListener])

net.connect(port[, host][, connectListener])

net.createConnection(port[, host][, connectListener])

net.connect(path[, connectListener])

net.createConnection(path[, connectListener])

net.isIP(input)

测试 input 是否 IP 地址。无效字符串返回 0;IP 版本 4 地址返回 4;IP 版本 6 地址返回 6

net.isIPv4(input)

如果 input 为版本 4 地址则返回 true,否则返回 false

net.isIPv6(input)

如果 input 为版本 6 地址则返回 true,否则返回 false


0 0
原创粉丝点击