Module basic module

Module net

Network access module

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

1
var net = require('net');

Object

Socket

Create a Socket object, see Socket

1
Socket net.Socket;

Smtp

Create an Smtp object, see Smtp

1
Smtp net.Smtp;

TcpServer

Create a TcpServer object, see TcpServer

1
TcpServer net.TcpServer;

Url

Create a 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 , returns 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 , returns 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 , returns the queried ipv6 string

connect

Create a 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
  • timeout : Integer, specify the timeout time, the unit is milliseconds, the default is 0

Return result:


openSmtp

Create an 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 time, the unit is milliseconds, the default is 0

Return result:

  • Smtp , returns the Smtp object of successful connection

backend

Query the current system asynchronous network engine

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 , an illegal IP address, returns 0, if it is IPv4, it returns 4, if it is IPv6, it returns 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 , returns true if it is IPv4, otherwise 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 , returns true if it is IPv6, otherwise returns false

constant

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;

SOCK_STREAM

Protocol family constant, specify tcp

1
const net.SOCK_STREAM = 1;

SOCK_DGRAM

Protocol family constant, specify udp

1
const net.SOCK_DGRAM = 2;