Module basic module

module net

network access module

Basic module. Can be used to create and operate network resources, reference method:

1
var net = require('net');

object

Socket

Create aSocketobject, seeSocket

1
Socket net.Socket;

Smtp

Create aSmtpobject, seeSmtp

1
Smtp net.Smtp;

TcpServer

Create aTcpServerobject, seeTcpServer

1
TcpServer net.TcpServer;

Url

Create aUrlObjectobject, seeUrlObject

1
UrlObject net.Url;

static function

info

Query the current operating environment network information

1
static Object net.info();

Return results:

  • Object, return network card information

resolve

Query the address of a 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, specifies the query return type, the default is AF_INET

Return results:

  • String, returns the queried IP string

ip

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 results:

  • String, returns the queried IP string

ipv6

Quickly query the host ipv6 address, equivalent to resolve(name,net.AF_INET6)

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

Call parameters:

  • name: String, specify the host name

Return results:

  • String, returns the queried ipv6 string

connect

Create aSocketorSslSocketobject and establish connection

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

Call parameters:

  • url: String, specifies the connection protocol, which can be: tcp://host:port orssl://host:port, it can also be: unix:/usr/local/proc1 or pipe://./pipe/proc1, it needs to be /replaced when connecting to the pipe\
  • timeout: Integer, specifies the timeout, the unit is milliseconds, the default is 0

Return results:


openSmtp

Create aSmtpobject and establish a connection, seeSmtp

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

Call parameters:

  • url: String, specifies the connection protocol, which can be: tcp://host:port orssl://host:port
  • timeout: Integer, specifies the timeout, the unit is milliseconds, the default is 0

Return results:

  • Smtp, returns successful connectionSmtpobject

backend

Query the current system asynchronous network engine

1
static String net.backend();

Return results:

  • String, returns the network engine name

isIP

Check if the input is an IP address

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

Call parameters:

  • ip: String, specifies the string to be detected

Return results:

  • Integer, illegal IP address, returns 0, if it is IPv4, returns 4, if it is IPv6, returns 6

isIPv4

Check if the input is an IPv4 address

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

Call parameters:

  • ip: String, specifies the string to be detected

Return results:

  • Boolean, if it is IPv4, return true. Otherwise, return false.

isIPv6

Check if the input is an IPv6 address

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

Call parameters:

  • ip: String, specifies the string to be detected

Return results:

  • Boolean, if it is IPv6, return true. Otherwise, return 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, specifying 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;