Package: io.vertx.groovy.core.datagram

## [Groovy] Class DatagramSocket

- io.vertx.groovy.core.datagram.DatagramSocket

- All Implemented Interfaces and Traits:
    Measured, ReadStream

      @groovy.transform.CompileStatic
      class DatagramSocket
      extends java.lang.Object

  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.

- - ### Constructor Summary

    Constructors
    Constructor and description
    `DatagramSocket (java.lang.Object delegate)`

  - ### Methods Summary

    Methods
    Type | Name and description
    --- | ---
    `DatagramSocket` | `blockMulticastGroup(java.lang.String multicastAddress, java.lang.String sourceToBlock, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)` Block the given address for the given multicast address and notifies the once the operation completes.
    `DatagramSocket` | `blockMulticastGroup(java.lang.String multicastAddress, java.lang.String networkInterface, java.lang.String sourceToBlock, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)` Block the given address for the given multicast address on the given network interface and notifies the once the operation completes.
    `void` | `close(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> handler)` Closes the DatagramSocket implementation asynchronous and notifies the handler once done.
    `void` | `close()` Closes the DatagramSocket.
    `DatagramSocket` | `endHandler(io.vertx.core.Handler<java.lang.Void> endHandler)`
    `DatagramSocket` | `exceptionHandler(io.vertx.core.Handler<java.lang.Throwable> handler)`
    `java.lang.Object` | `getDelegate()`
    `DatagramSocket` | `handler(io.vertx.core.Handler<DatagramPacket> handler)`
    `boolean` | `isMetricsEnabled()` Whether the metrics are enabled for this measured object
    `DatagramSocket` | `listen(int port, java.lang.String host, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)` Start listening on the given port and host.
    `DatagramSocket` | `listenMulticastGroup(java.lang.String multicastAddress, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)` Joins a multicast group and listens for packets send to it.
    `DatagramSocket` | `listenMulticastGroup(java.lang.String multicastAddress, java.lang.String networkInterface, java.lang.String source, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)` Joins a multicast group and listens for packets send to it on the given network interface.
    `SocketAddress` | `localAddress()` Return the SocketAddress to which this DatagramSocket is bound.
    `DatagramSocket` | `pause()`
    `DatagramSocket` | `resume()`
    `DatagramSocket` | `send(Buffer packet, int port, java.lang.String host, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)` Write the given Buffer to the SocketAddress.
    `DatagramSocket` | `send(java.lang.String str, int port, java.lang.String host, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)` Write the given java.lang.String to the SocketAddress using UTF8 encoding.
    `DatagramSocket` | `send(java.lang.String str, java.lang.String enc, int port, java.lang.String host, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)` Write the given java.lang.String to the SocketAddress using the given encoding.
    `PacketWritestream` | `sender(int port, java.lang.String host)` Returns a PacketWritestream able to send to the SocketAddress.
    `DatagramSocket` | `unlistenMulticastGroup(java.lang.String multicastAddress, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)` Leaves a multicast group and stops listening for packets send to it.
    `DatagramSocket` | `unlistenMulticastGroup(java.lang.String multicastAddress, java.lang.String networkInterface, java.lang.String source, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)` Leaves a multicast group and stops listening for packets send to it on the given network interface.

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class java.lang.Object` | `java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll()`

- - ### Constructor Detail

    - #### DatagramSocket(java.lang.Object delegate)

  - ### Method Detail

    - #### DatagramSocket blockMulticastGroup(java.lang.String multicastAddress, java.lang.String sourceToBlock, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)

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

      Returns:
        a reference to this, so the API can be used fluently
      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

    - #### DatagramSocket blockMulticastGroup(java.lang.String multicastAddress, java.lang.String networkInterface, java.lang.String sourceToBlock, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)

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

      Returns:
        a reference to this, so the API can be used fluently
      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

    - #### void close(io.vertx.core.Handler<io.vertx.core.AsyncResult<java.lang.Void>> handler)

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

      Parameters:
        `handler` - the handler to notify once complete

    - #### void close()

      Closes the DatagramSocket. The close itself is asynchronous.

    - #### DatagramSocket endHandler(io.vertx.core.Handler<java.lang.Void> endHandler)

    - #### DatagramSocket exceptionHandler(io.vertx.core.Handler<java.lang.Throwable> handler)

    - #### java.lang.Object getDelegate()

    - #### DatagramSocket handler(io.vertx.core.Handler<DatagramPacket> handler)

    - #### boolean isMetricsEnabled()

      Whether the metrics are enabled for this measured object

      Returns:
        true if the metrics are enabled

    - #### DatagramSocket listen(int port, java.lang.String host, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)

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

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `port` - the port to listen on
        `host` - the host to listen on
        `handler` - the handler will be called when listening

    - #### DatagramSocket listenMulticastGroup(java.lang.String multicastAddress, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)

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

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `multicastAddress` - the address of the multicast group to join
        `handler` - then handler to notify once the operation completes

    - #### DatagramSocket listenMulticastGroup(java.lang.String multicastAddress, java.lang.String networkInterface, java.lang.String source, io.vertx.core.Handler<io.vertx.core.AsyncResult<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.

      Returns:
        a reference to this, so the API can be used fluently
      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

    - #### SocketAddress localAddress()

      Return the SocketAddress to which this DatagramSocket is bound.

      Returns:
        the socket address

    - #### DatagramSocket pause()

    - #### DatagramSocket resume()

    - #### DatagramSocket send(Buffer packet, int port, java.lang.String host, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)

      Write the given Buffer to the SocketAddress. The io.vertx.groovy.core.Handler will be notified once the write completes.

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `packet` - the Buffer to write
        `port` - the host port of the remote peer
        `host` - the host address of the remote peer
        `handler` - the io.vertx.groovy.core.Handler to notify once the write completes.

    - #### DatagramSocket send(java.lang.String str, int port, java.lang.String host, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)

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

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `str` - the java.lang.String to write
        `port` - the host port of the remote peer
        `host` - the host address of the remote peer
        `handler` - the io.vertx.groovy.core.Handler to notify once the write completes.

    - #### DatagramSocket send(java.lang.String str, java.lang.String enc, int port, java.lang.String host, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)

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

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `str` - the java.lang.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 io.vertx.groovy.core.Handler to notify once the write completes.

    - #### PacketWritestream sender(int port, java.lang.String host)

      Returns a PacketWritestream able to send to the SocketAddress.

      Returns:
        the write stream for sending packets
      Parameters:
        `port` - the port of the remote peer
        `host` - the host address of the remote peer

    - #### DatagramSocket unlistenMulticastGroup(java.lang.String multicastAddress, io.vertx.core.Handler<io.vertx.core.AsyncResult<DatagramSocket>> handler)

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

      Returns:
        a reference to this, so the API can be used fluently
      Parameters:
        `multicastAddress` - the address of the multicast group to leave
        `handler` - then handler to notify once the operation completes

    - #### DatagramSocket unlistenMulticastGroup(java.lang.String multicastAddress, java.lang.String networkInterface, java.lang.String source, io.vertx.core.Handler<io.vertx.core.AsyncResult<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.

      Returns:
        a reference to this, so the API can be used fluently
      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