new DatagramSocket(ipv4)
A socket which can be used to send and receive module:vertx/datagram~DatagramPacket
s
UDP is connectionless which means you are not connected to the remote peer in a persistent way. Because of this you have to supply the address and port of the remote peer when sending data. You can send data to ipv4 or ipv6 addresses, which also include multicast addresses.
Parameters:
Name | Type | Description |
---|---|---|
ipv4 |
boolean | If true, use IPv4 addresses, if false use IPv6 addresses, if undefined, use the operating system default. |
- Source:
Extends
Methods
-
blockMulticastGroup(address, handler, source, networkInterface) → {module:vertx/datagram~DatagramSocket}
-
Blocks the given source address on the given network interface notifies the handler when this operation has completed.
Parameters:
Name Type Argument Description address
string The address of the multicast group on which the source is broadcasting handler
ResultHandler The handler to notify when the operation completes source
string The source address to block networkInterface
string <optional>
The network interface this socket is currently listening on - Source:
Returns:
this -
broadcast(value) → {boolean|module:vertx/datagram~DatagramSocket}
-
Get or set the SO_BROADCAST option
Parameters:
Name Type Argument Description value
boolean <optional>
turns on or off the SO_BROADCAST option - Source:
Returns:
the SO_BROADCAST option as currently set or this- Type
- boolean | module:vertx/datagram~DatagramSocket
-
close(handler)
-
Close the
module:vertx/datagram~DatagramSocket
asynchronously and notify the handler when complete.Parameters:
Name Type Description handler
ResultHandler the handler to notify when close() has completed. - Source:
-
dataHandler(handler)
-
Set a
PacketHandler
to be notified of incoming data.Parameters:
Name Type Description handler
PacketHandler The handler to be notified of incoming packets. - Source:
-
drainHandler(handler)
-
Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue has been reduced to maxSize/2. See
module:vertx/pump~Pump
for an example of this being used.Parameters:
Name Type Description handler
Handler the handler to call when the stream has been drained - Inherited From:
- Source:
-
exceptionHandler(handler)
-
Set an exception handler.
Parameters:
Name Type Description handler
Handler the handler to call - Inherited From:
- Source:
-
exceptionHandler(handler)
-
Set an exception handler on the stream
Parameters:
Name Type Description handler
Handler the handler to call when an exception occurs - Inherited From:
- Source:
-
listen(port, host, handler)
-
Listens to broadcast messages on the given port and optional host address. The handler is notified when the listen operation has completed.
Parameters:
Name Type Argument Description port
number The port to listen on for incoming packets host
string <optional>
The host address to listen on. Defaults to '0.0.0.0'. handler
ResultHandler <optional>
The handler to notify when the listen operation completes - Source:
-
listenMulticastGroup(address, handler, source, networkInterface) → {module:vertx/datagram~DatagramSocket}
-
Joins a multicast group and listens for packets sent to it. The
ResultHandler
is notified once the operation completes.Parameters:
Name Type Argument Description address
string The address of the multicast group to join handler
ResultHandler The handler to notify when the operation has completed source
string <optional>
The address of the source to which we'll listen for packets networkInterface
string <optional>
The network interface on which to listen for packets - Source:
Returns:
this -
localAddress()
-
Get the local address of this socket.
- Source:
Returns:
An object with the socket's address, port and IP family as properties -
multicastLoopbackMode(value) → {boolean|module:vertx/datagram~DatagramSocket}
-
Get or set the IP_MULTICAST_LOOP option
Parameters:
Name Type Argument Description value
boolean <optional>
turns on or off the IP_MULTICAST_LOOP option - Source:
Returns:
the IP_MULTICAST_LOOP option as currently set or this- Type
- boolean | module:vertx/datagram~DatagramSocket
-
multicastNetworkInterface(value) → {string|module:vertx/datagram~DatagramSocket}
-
Get or set the IP_MULTICAST_IF option
Parameters:
Name Type Argument Description value
string <optional>
the IP_MULTICAST_IF value - Source:
Returns:
the IP_MULTICAST_IF option as currently set or this- Type
- string | module:vertx/datagram~DatagramSocket
-
multicastTimeToLive(value) → {number|module:vertx/datagram~DatagramSocket}
-
Get or set the IP_MULTICAST_TTL option
Parameters:
Name Type Argument Description value
number <optional>
the IP_MULTICAST_TTL value - Source:
Returns:
the IP_MULTICAST_TTL option as currently set or this- Type
- number | module:vertx/datagram~DatagramSocket
-
pause()
-
Pause the
ReadStream
. While the stream is paused, no data will be sent to the data Handler- Inherited From:
- Source:
-
receiveBufferSize(size) → {number|Object}
-
Set or get the receive buffer size
Parameters:
Name Type Argument Description size
number <optional>
If provided, set the value; if not, returns the current value. - Inherited From:
- Source:
Returns:
the value or this- Type
- number | Object
-
resume()
-
Resume reading. If the
ReadStream
has been paused, reading will recommence on it.- Inherited From:
- Source:
-
reuseAddress(reuse) → {boolean|Object}
-
Set or get the TCP reuse address value
Parameters:
Name Type Argument Description reuse
boolean <optional>
If provided, set the value; if not, returns the current value. - Inherited From:
- Source:
Returns:
the value or this- Type
- boolean | Object
-
send(host, port, packet, handler, encoding)
-
Writes a packet to the host and port provided, calling the handler when the write has completed. If an encoding is supplied, the packet's toString function is called and the specified encoding is used.
Parameters:
Name Type Argument Description host
string the network host address of the remote peer port
number the network port of the remote peer packet
string | module:vertx/buffer the packet to write handler
ResultHandler the handler to notify when the write completes encoding
string <optional>
the encoding to use when writing a string packet - Source:
-
sendBufferSize(size) → {number|Object}
-
Set or get the send buffer size
Parameters:
Name Type Argument Description size
number <optional>
If provided, set the value; if not, returns the current value. - Inherited From:
- Source:
Returns:
the value or this- Type
- number | Object
-
trafficClass(class) → {number|Object}
-
Set or get the TCP traffic class
Parameters:
Name Type Argument Description class
number <optional>
If provided, set the value; if not, returns the current value. - Inherited From:
- Source:
Returns:
the value or this- Type
- number | Object
-
unlistenMulticastGroup(address, handler, source, networkInterface) → {module:vertx/datagram~DatagramSocket}
-
Leaves a multicast group and stops listening for packets sent to it on the given network interface. The {@linkcode
Parameters:
Name Type Argument Description address
string The address of the multicast group to stop listening to handler
ResultHandler The handler to notify when the operation completes source
string <optional>
The source address to stop listening to networkInterface
string <optional>
The network interface this socket is currently listening on - Source:
Returns:
this -
writeQueueFull()
-
This will return
true
if there are more bytes in the write queue than the value set usingwriteQueueMaxSize
- Inherited From:
- Source:
-
writeQueueMaxSize(size)
-
Set the maximum size of the write queue to
maxSize
. You will still be able to write to the stream even if there is more thanmaxSize
bytes in the write queue. This is used as an indicator by classes such asPump
to provide flow control.Parameters:
Name Type Description size
number the size of the write queue - Inherited From:
- Source: