module net
network access module
Basic module. Can be used to create and operate network resources, reference method:
1var net = require('net');
object
Socket
Create aSocketobject, seeSocket
1Socket net.Socket;
Smtp
1Smtp net.Smtp;
TcpServer
Create aTcpServerobject, seeTcpServer
1TcpServer net.TcpServer;
Url
Create aUrlObjectobject, seeUrlObject
1UrlObject net.Url;
static function
info
Query the current operating environment network information
1static Object net.info();
Return results:
- Object, return network card information
resolve
Query the address of a given hostname
1
2static 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)
1static 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)
1static 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
2static 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
2static 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:
backend
Query the current system asynchronous network engine
1static String net.backend();
Return results:
- String, returns the network engine name
isIP
Check if the input is an IP address
1static 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
1static 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
1static 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
1static Boolean net.use_uv_socket;
constant
AF_UNIX
Address set constant, specifying unix socket
1const net.AF_UNIX = 1;
AF_PIPE
Address set constant, specify Windows pipe
1const net.AF_PIPE = 1;
AF_INET
Address set constant, specify ipv4
1const net.AF_INET = 2;
AF_INET6
Address set constant, specify ipv6
1const net.AF_INET6 = 10;