Module basic module

Module net

Network access module

Basic module. It can be used to create and operate network resources, the way of reference:

1
var net = require('net');

Object

Socket

Create Socket Object, see Socket

1
Socket net.Socket;

Smtp

Create Smtp Object, see Smtp

1
Smtp net.Smtp;

TcpServer

Create TcpServer Object, see TcpServer

1
TcpServer net.TcpServer;

Url

Create UrlObject Object, see UrlObject

1
UrlObject net.Url;

Static function

info

Query current operating environment network information

1
static Object net.info();

Return result:

  • Object, Return network card information

resolve

Query the address of the given hostname

1 2
static String net.resolve(String name, Integer family = AF_INET) async;

Call parameters:

  • name: String, specify the host name
  • family: Integer, specify the query return type, the default is AF_INET

Return result:

  • String, Return the queried ip string

ip

The host address for quick query, equivalent to resolve(name)

1
static String net.ip(String name) async;

Call parameters:

  • name: String, specify the host name

Return result:

  • String, Return the queried ip string

ipv6

The host ipv6 address for quick query, which is equivalent to resolve(name, net.AF_INET6)

1
static String net.ipv6(String name) async;

Call parameters:

  • name: String, specify the host name

Return result:

  • String, Return the queried ipv6 string

connect

Create Socket or SslSocket Object and establish a connection

1 2
static Stream net.connect(String url, Integer timeout = 0) async;

Call parameters:

  • url: String, specify the connection protocol, it can be: tcp://host:port or ssl: // host: port, may be: unix: / usr / local / proc1 or pipe: //./pipe/proc1, pipe connections need /replacing\
  • timeout: Integer, specify the timeout period, the unit is milliseconds, the default is 0

Return result:


openSmtp

Create Smtp Object and establish a connection, see Smtp

1 2
static Smtp net.openSmtp(String url, Integer timeout = 0) async;

Call parameters:

  • url: String, specify the connection protocol, it can be: tcp://host:port or ssl://host:port
  • timeout: Integer, specify the timeout period, the unit is milliseconds, the default is 0

Return result:

  • Smtp, Return the successful connection Smtp Object

backend

Query the asynchronous network engine of the current system

1
static String net.backend();

Return result:

  • String, Returns the name of the network engine

isIP

Check if the input is an IP address

1
static Integer net.isIP(String ip = "");

Call parameters:

  • ip: String, specify the string to be detected

Return result:

  • Integer, Illegal IP address, return 0, if it is IPv4, return 4, if it is IPv6, return 6

isIPv4

Check if the input is an IPv4 address

1
static Boolean net.isIPv4(String ip = "");

Call parameters:

  • ip: String, specify the string to be detected

Return result:

  • Boolean, If it is IPv4, it returns true. Otherwise, it returns false

isIPv6

Check if the input is an IPv6 address

1
static Boolean net.isIPv6(String ip = "");

Call parameters:

  • ip: String, specify the string to be detected

Return result:

  • Boolean, If it is IPv6, it returns true. Otherwise, it returns false

Static properties

use_uv_socket

Boolean, query and set whether the socket backend uses uv, the default is false

1
static Boolean net.use_uv_socket;

constant

AF_UNIX

Address set constant, specify unix socket

1
const net.AF_UNIX = 1;

AF_PIPE

Address set constant, specify Windows pipe

1
const net.AF_PIPE = 1;

AF_INET

Address set constant, specify ipv4

1
const net.AF_INET = 2;

AF_INET6

Address set constant, specify ipv6

1
const net.AF_INET6 = 10;