Module supporting UDP (datagram) sockets.
Methods
(static) createSocket(type, callback, enableBroadcast)
Create a socket of the specified type. This returns an instance of the Socket class.
Parameters:
Name | Type | Description |
---|---|---|
type |
One of "udp4" or "udp6". Defaults to "udp4" if not given. |
|
callback |
Optional function to bind to "message" events. |
|
enableBroadcast |
Boolean to enable broadcasting or not |
- Source:
(static) Socket(type, enableBroadcast)
Construct an instance of a UDP (datagram) socket that can send or receive messages. To receive messages, call bind() on the returned object. To send messages, call send(). The returned object is an event emitter that emits 'listening', 'message', 'close', or 'error'. For example,
var UDPSocket = require('udpSocket'); var socket = UDPSocket.createSocket(); socket.on('message', function(message) { print('Received from web socket: ' + message); }); socket.bind(8084);This class is fashioned after the Socket class in Node's dgram module, with the only exception being that the messages it emits are not instances of Buffer, but rather appropriate data types as specified by the receiveType argument to setReceiveType(). Similarly, the data provided to send() will be converted to a Buffer according to the type set by setSendType().
Node dgram module: https://nodejs.org/api/dgram.html
Parameters:
Name | Type | Description |
---|---|---|
type |
One of "udp4" or "udp6". |
|
enableBroadcast |
boolean, setting to true enables the socket broadcast messages. |
- Source:
(static) supportedReceiveTypes()
Return an array of the types supported by the current host for receiveType arguments.
- Source:
(static) supportedSendTypes()
Return an array of the types supported by the current host for sendType arguments.