Some api~ of Nodejs (iv) UDP&DNS

Source: Internet
Author: User
Tags mail exchange

Remember today udp/datagram sockets and DNS.

Udp

udp/Datagram socket = require (' Dgram ');
Dgram.createserver ([TYPE],[CB]);
Type: Can be ' udp4 ', ' udp6 ';
Cb:message event Listener;
Returns the Socket object
You can call Socket.bind if you want to receive datagrams. Socket.bind () binds to a random port of "All network Interface" addresses (both UDP4 and UDP6)
You can then get the address and port by Socket.address (). Addr and Socket.address (). Port.
Class Dgram. The Socket//encapsulates the datagram function, which can be created via Createsocket
Event message msg buffer object, message; rinfo obj remote address information;

Socket.on (' message ',function(msg,rinfo) {    Console.log (' received%d bytes, from%s:%d\n ', Msg.length, Rinfo.address,rinfo.port);})

Event listening The socket starts listening for the datagram, which occurs when the UDP socket is created
Event Close, error
Socket.send (BUF,OFFSET,LENGTH,PORT,ADDRESS,[CB])
BUF Buffer object, the message to be sent
The start offset value of the message in offset Integer,buffer.
Length Integer, the number of bytes of the message.
Port Integer, Destination ports
Address String, Destination IP
Callback Function, optional, callback when message is posted
For UDP sockets, the template port and the ip,address parameter must be established but a string that he will be parsed by DNS;
Socket.bind (PORT,[ADDRESS],[CB]);
Port integer;address String Optional
For UDP sockets, listen for data on a named port and an optional address.
Socket.close ();
Socket.address ();
Socket.setbroadcast (flag); Sets or clears the SO_BROADCAST socket option. When this option is set, the UDP message may be sent to the broadcast address of a local interface;
Socket.setttl (TTL); Sets the IP_TTL socket option; The number of hops with a parameter of 1-255. Most systems default to 64;
Socket.setmulticastttl (TTL) sets the IP_MULTICAST_TTL socket option.
Socket.unref () ...
Socket.ref ()
DNS
Dns.lookup (domain, [family], callback);//resolves a domain name to the first found record of a (IPv4) or AAAA record (IPv6)
Address family family can be 4,6. The default is null. Callback parameter is CB (err,address,family)
Dns.resolve (DOMAIN,[RRTYPE],CB)//resolves a domain name to an array rrtype the specified record type. Valid Rrytype values are A,aaaa,mx,tx,srv,ptr,ns,cname
The callback parameter is (err,addresses) where the type of each item in addresses depends on the record type;
DNS.RESOLVE4/6 (DOMAIN,CB)//For querying IPV4 records only; addresses is an array of IPv4 addresses;
Dns.resolvemx (DOMAIN,CB); similar to resolve but used for mail exchange queries (MX records)
Dns.relovetxt/srv/cname/ns (DOMAIN,CB);
Dns.reverse (IP,CB); echo resolves the IP address, returning an array of domain names that point to that IP address; CB (Err,domains)
Dns.getservers (); The string returns an array of IP addresses currently being used for parsing;
Dns.setservers (servers) specifies an array of IP address strings to use as a server for parsing

Some api~ of Nodejs (iv) UDP&DNS

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.