Interface DatagramSocket

  • All Superinterfaces:
    Measured

    public interface DatagramSocket
    extends Measured
    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.

    Author:
    Norman Maurer
    • Method Detail

      • send

        Future<Void> send​(Buffer packet,
                          int port,
                          String host)
        Write the given Buffer to the SocketAddress.
        Parameters:
        packet - the Buffer to write
        port - the host port of the remote peer
        host - the host address of the remote peer
        Returns:
        a future notified once the write completes.
      • sender

        WriteStream<Buffer> sender​(int port,
                                   String host)
        Returns a WriteStream<Buffer> able to send Buffer to the SocketAddress.
        Parameters:
        port - the port of the remote peer
        host - the host address of the remote peer
        Returns:
        the write stream for sending packets
      • send

        Future<Void> send​(String str,
                          int port,
                          String host)
        Write the given String to the SocketAddress using UTF8 encoding.
        Parameters:
        str - the String to write
        port - the host port of the remote peer
        host - the host address of the remote peer
        Returns:
        a future notified once the write completes.
      • send

        Future<Void> send​(String str,
                          String enc,
                          int port,
                          String host)
        Write the given String to the SocketAddress using the given encoding.
        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
        Returns:
        a future notified once the write completes.
      • close

        Future<Void> close()
        Closes the DatagramSocket implementation asynchronous and notifies the handler once done.
        Returns:
        a future notified once the socket is closed
      • listenMulticastGroup

        Future<Void> listenMulticastGroup​(String multicastAddress)
        Joins a multicast group and listens for packets send to it.
        Parameters:
        multicastAddress - the address of the multicast group to join
        Returns:
        a future notified once the operation completes
      • listenMulticastGroup

        Future<Void> listenMulticastGroup​(String multicastAddress,
                                          String networkInterface,
                                          String source)
        Joins a multicast group and listens for packets send to it on the given network interface.
        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
        Returns:
        a future notified once the operation completes
      • unlistenMulticastGroup

        Future<Void> unlistenMulticastGroup​(String multicastAddress)
        Leaves a multicast group and stops listening for packets send to it.
        Parameters:
        multicastAddress - the address of the multicast group to leave
        Returns:
        a future notified once the operation completes
      • unlistenMulticastGroup

        Future<Void> unlistenMulticastGroup​(String multicastAddress,
                                            String networkInterface,
                                            String source)
        Leaves a multicast group and stops listening for packets send to it on the given network interface.
        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
        Returns:
        a future notified once the operation completes
      • blockMulticastGroup

        Future<Void> blockMulticastGroup​(String multicastAddress,
                                         String sourceToBlock)
        Block the given address for the given multicast address and notifies the Handler 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.
        Returns:
        a future notified once the operation completes
      • blockMulticastGroup

        Future<Void> blockMulticastGroup​(String multicastAddress,
                                         String networkInterface,
                                         String sourceToBlock)
        Block the given address for the given multicast address on the given network interface and notifies the Handler 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.
        Returns:
        a future notified once the operation completes
      • listen

        Future<DatagramSocket> listen​(int port,
                                      String host)
        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
        Returns:
        a future notified once the operation completes