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 object is a function of encapsulating a packet functionality EventEmitter . See DgramSocket

1
DgramSocket dgram.Socket;

dgram.Socket instance is created by dgram.createSocket (). dgram.Socket no need to use the new keyword to create dgram.Socket instance of dgram.Socket .

Static function

createSocket

Create a 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
{ "type": "udp4" | "udp6", // 必填 "reuseAddr": true | false, //若设置为 true,socket.bind() 则会重用地址,即时另一个进程已经在其上面绑定了一个套接字。 默认是 false "recvBufferSize": 1024, // 设置 SO_RCVBUF 套接字值 "sendBufferSize": 1024 //设置 SO_RCVBUF 套接字值 }

Create a 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
{ "type": "udp4" | "udp6", // 必填 "reuseAddr": true | false, //若设置为 true,socket.bind() 则会重用地址,即时另一个进程已经在其上面绑定了一个套接字。 默认是 false "recvBufferSize": # # #, // 设置 SO_RCVBUF 套接字值 "sendBufferSize": # # # //设置 SO_RCVBUF 套接字值 }

Create a dgram.Socket object

1
static DgramSocket dgram.createSocket(String type);

Call parameters:

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

Return result:


Create a 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: