Module basic module

Module dgram

The dgram module provides the implementation of UDP packet socket

Basic module, reference method:

1
var dgram = require('dgram');

Object

Socket

dgram.Socket The object is a package that encapsulates the function of the data packet EventEmitter. SeeDgramSocket

1
DgramSocket dgram.Socket;

dgram.Socket The instance is made by dgram.createSocket() Created. createdgram.Socket The instance does not need to use the new keyword.

Static function

createSocket

Create dgram.Socket Object

1
static DgramSocket dgram.createSocket(Object opts);

Call parameters:

  • opts: Object,

Return result:

The allowed options for opts are:

1 2 3 4 5 6 7
{ "type": "udp4" | "udp6", // 必填 "reuseAddr": true | false, // 若设置为 true,socket.bind() 则会重用地址,即时另一个进程已经在其上面绑定了一个套接字。 默认是 false "ipv6Only": true | false, // 若设置为 true,socket.bind() 将只接收 IPv6 的数据包。 默认是 false "recvBufferSize": 1024, // 设置 SO_RCVBUF 套接字值 "sendBufferSize": 1024 //设置 SO_RCVBUF 套接字值 }

Create dgram.Socket Object

1 2
static DgramSocket dgram.createSocket(Object opts, Function callback);

Call parameters:

  • opts: Object,
  • callback: Function, add a listener for the'message' event.

Return result:

The allowed options for opts are:

1 2 3 4 5 6 7
{ "type": "udp4" | "udp6", // 必填 "reuseAddr": true | false, // 若设置为 true,socket.bind() 则会重用地址,即时另一个进程已经在其上面绑定了一个套接字。 默认是 false "ipv6Only": true | false, // 若设置为 true,socket.bind() 将只接收 IPv6 的数据包。 默认是 false "recvBufferSize": ###, // 设置 SO_RCVBUF 套接字值 "sendBufferSize": ### //设置 SO_RCVBUF 套接字值 }

Create dgram.Socket Object

1
static DgramSocket dgram.createSocket(String type);

Call parameters:

  • type: String, socket family,'udp4' or'udp6'.

Return result:


Create dgram.Socket Object

1 2
static DgramSocket dgram.createSocket(String type, Function callback);

Call parameters:

  • type: String, socket family,'udp4' or'udp6'.
  • callback: Function, add a listener for the'message' event.

Return result: