A datagram socket can be used to send DatagramPacket's to remote datagram servers and receive DatagramPackets .

Usually you use a datagram socket to send UDP over the wire. UDP is connection-less 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.

Please consult the documentation for more information on datagram sockets.

no subtypes hierarchy

Initializer
DatagramSocket(DatagramSocket unknown)
Inherited Attributes
Attributes inherited from: Object
hash, string
Methods
blockMulticastGroupshared default DatagramSocket blockMulticastGroup(String multicastAddress, String sourceToBlock, Anything(Throwable|DatagramSocket) handler)

Block the given address for the given multicast address and notifies the once the operation completes.

Parameters:
  • multicastAddress

    the address for which you want to block the source address

  • sourceToBlock

    the source address which should be blocked. You will not receive an multicast packets for it anymore.

  • handler

    the handler to notify once the operation completes

blockMulticastGroupshared default DatagramSocket blockMulticastGroup(String multicastAddress, String networkInterface, String sourceToBlock, Anything(Throwable|DatagramSocket) handler)

Block the given address for the given multicast address on the given network interface and notifies the once the operation completes.

Parameters:
  • multicastAddress

    the address for which you want to block the source address

  • networkInterface

    the network interface on which the blocking should occur.

  • sourceToBlock

    the source address which should be blocked. You will not receive an multicast packets for it anymore.

  • handler

    the handler to notify once the operation completes

closeshared default void close()

Closes the DatagramSocket. The close itself is asynchronous.

closeshared default void close(Anything(Throwable?) handler)

Closes the DatagramSocket implementation asynchronous and notifies the handler once done.

Parameters:
  • handler

    the handler to notify once complete

endHandlershared actual default DatagramSocket endHandler(Anything()? endHandler)

Set an end handler. Once the stream has ended, and there is no more data to be read, this handler will be called.

exceptionHandlershared actual default DatagramSocket exceptionHandler(Anything(Throwable)? handler)

Set an exception handler.

handlershared actual default DatagramSocket handler(Anything(DatagramPacket)? handler)

Set a data handler. As data is read, the handler will be called with the data.

isMetricsEnabledshared actual default Boolean isMetricsEnabled()

Whether the metrics are enabled for this measured object

listenshared default DatagramSocket listen(Integer port, String host, Anything(Throwable|DatagramSocket) handler)

Start listening on the given port and host. The handler will be called when the socket is listening.

Parameters:
  • port

    the port to listen on

  • host

    the host to listen on

  • handler

    the handler will be called when listening

listenMulticastGroupshared default DatagramSocket listenMulticastGroup(String multicastAddress, Anything(Throwable|DatagramSocket) handler)

Joins a multicast group and listens for packets send to it. The is notified once the operation completes.

Parameters:
  • multicastAddress

    the address of the multicast group to join

  • handler

    then handler to notify once the operation completes

listenMulticastGroupshared default DatagramSocket listenMulticastGroup(String multicastAddress, String networkInterface, String? source, Anything(Throwable|DatagramSocket) handler)

Joins a multicast group and listens for packets send to it on the given network interface. The is notified once the operation completes.

Parameters:
  • multicastAddress

    the address of the multicast group to join

  • networkInterface

    the network interface on which to listen for packets.

  • source

    the address of the source for which we will listen for multicast packets

  • handler

    then handler to notify once the operation completes

localAddressshared default SocketAddress localAddress()

Return the SocketAddress to which this DatagramSocket is bound.

pauseshared actual default DatagramSocket pause()

Pause the ReadSupport. While it's paused, no data will be sent to the dataHandler

resumeshared actual default DatagramSocket resume()

Resume reading. If the ReadSupport has been paused, reading will recommence on it.

sendshared default DatagramSocket send(Buffer packet, Integer port, String host, Anything(Throwable|DatagramSocket) handler)

Write the given Buffer to the SocketAddress. The handler will be notified once the write completes.

Parameters:
  • packet

    the Buffer to write

  • port

    the host port of the remote peer

  • host

    the host address of the remote peer

  • handler

    the handler to notify once the write completes.

sendshared default DatagramSocket send(String str, Integer port, String host, Anything(Throwable|DatagramSocket) handler)

Write the given String to the SocketAddress using UTF8 encoding. The will be notified once the write completes.

Parameters:
  • str

    the String to write

  • port

    the host port of the remote peer

  • host

    the host address of the remote peer

  • handler

    the handler to notify once the write completes.

sendshared default DatagramSocket send(String str, String enc, Integer port, String host, Anything(Throwable|DatagramSocket) handler)

Write the given String to the SocketAddress using the given encoding. The will be notified once the write completes.

Parameters:
  • str

    the String to write

  • enc

    the charset used for encoding

  • port

    the host port of the remote peer

  • host

    the host address of the remote peer

  • handler

    the handler to notify once the write completes.

sendershared default WriteStream<Buffer> sender(Integer port, String host)

Returns a WriteStream able to send to the SocketAddress.

Parameters:
  • port

    the port of the remote peer

  • host

    the host address of the remote peer

unlistenMulticastGroupshared default DatagramSocket unlistenMulticastGroup(String multicastAddress, Anything(Throwable|DatagramSocket) handler)

Leaves a multicast group and stops listening for packets send to it. The is notified once the operation completes.

Parameters:
  • multicastAddress

    the address of the multicast group to leave

  • handler

    then handler to notify once the operation completes

unlistenMulticastGroupshared default DatagramSocket unlistenMulticastGroup(String multicastAddress, String networkInterface, String? source, Anything(Throwable|DatagramSocket) handler)

Leaves a multicast group and stops listening for packets send to it on the given network interface. The is notified once the operation completes.

Parameters:
  • multicastAddress

    the address of the multicast group to join

  • networkInterface

    the network interface on which to listen for packets.

  • source

    the address of the source for which we will listen for multicast packets

  • handler

    the handler to notify once the operation completes

Inherited Methods
Methods inherited from: Object
equals
Methods inherited from: Measured
Methods inherited from: ReadStream<T>
Methods inherited from: StreamBase