Class DatagramSocket

  • All Implemented Interfaces:
    Measured, ReadStream<DatagramPacket>, StreamBase

    public class DatagramSocket
    extends Object
    implements ReadStream<DatagramPacket>, 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.

    NOTE: This class has been automatically generated from the original non RX-ified interface using Vert.x codegen.

    • Constructor Detail

      • DatagramSocket

        public DatagramSocket​(Object delegate)
    • Method Detail

      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • isMetricsEnabled

        public boolean isMetricsEnabled()
        Whether the metrics are enabled for this measured object
        Specified by:
        isMetricsEnabled in interface Measured
        Returns:
        true if metrics are enabled
      • pipe

        public Pipe<DatagramPacket> pipe()
        Pause this stream and return a to transfer the elements of this stream to a destination .

        The stream will be resumed when the pipe will be wired to a WriteStream.

        Specified by:
        pipe in interface ReadStream<DatagramPacket>
        Returns:
        a pipe
      • pipeTo

        public void pipeTo​(WriteStream<DatagramPacket> dst,
                           Handler<AsyncResult<Void>> handler)
        Pipe this ReadStream to the WriteStream.

        Elements emitted by this stream will be written to the write stream until this stream ends or fails.

        Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

        Specified by:
        pipeTo in interface ReadStream<DatagramPacket>
        Parameters:
        dst - the destination write stream
        handler -
      • pipeTo

        public void pipeTo​(WriteStream<DatagramPacket> dst)
        Pipe this ReadStream to the WriteStream.

        Elements emitted by this stream will be written to the write stream until this stream ends or fails.

        Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

        Specified by:
        pipeTo in interface ReadStream<DatagramPacket>
        Parameters:
        dst - the destination write stream
      • rxPipeTo

        public io.reactivex.Completable rxPipeTo​(WriteStream<DatagramPacket> dst)
        Pipe this ReadStream to the WriteStream.

        Elements emitted by this stream will be written to the write stream until this stream ends or fails.

        Once this stream has ended or failed, the write stream will be ended and the handler will be called with the result.

        Specified by:
        rxPipeTo in interface ReadStream<DatagramPacket>
        Parameters:
        dst - the destination write stream
        Returns:
      • send

        public DatagramSocket send​(Buffer packet,
                                   int port,
                                   String host,
                                   Handler<AsyncResult<Void>> 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.
        Returns:
        a reference to this, so the API can be used fluently
      • send

        public DatagramSocket send​(Buffer packet,
                                   int port,
                                   String host)
        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
        Returns:
        a reference to this, so the API can be used fluently
      • rxSend

        public io.reactivex.Completable rxSend​(Buffer packet,
                                               int port,
                                               String host)
        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
        Returns:
        a reference to this, so the API can be used fluently
      • sender

        public WriteStream<Buffer> sender​(int 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
        Returns:
        the write stream for sending packets
      • send

        public DatagramSocket send​(String str,
                                   int port,
                                   String host,
                                   Handler<AsyncResult<Void>> 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.
        Returns:
        a reference to this, so the API can be used fluently
      • send

        public DatagramSocket send​(String str,
                                   int port,
                                   String host)
        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
        Returns:
        a reference to this, so the API can be used fluently
      • rxSend

        public io.reactivex.Completable rxSend​(String str,
                                               int port,
                                               String host)
        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
        Returns:
        a reference to this, so the API can be used fluently
      • send

        public DatagramSocket send​(String str,
                                   String enc,
                                   int port,
                                   String host,
                                   Handler<AsyncResult<Void>> 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.
        Returns:
        a reference to this, so the API can be used fluently
      • send

        public DatagramSocket send​(String str,
                                   String enc,
                                   int port,
                                   String host)
        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
        Returns:
        a reference to this, so the API can be used fluently
      • rxSend

        public io.reactivex.Completable rxSend​(String str,
                                               String enc,
                                               int port,
                                               String host)
        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
        Returns:
        a reference to this, so the API can be used fluently
      • close

        public void close​(Handler<AsyncResult<Void>> handler)
        Closes the DatagramSocket implementation asynchronous and notifies the handler once done.
        Parameters:
        handler - the handler to notify once complete
      • close

        public void close()
        Closes the DatagramSocket implementation asynchronous and notifies the handler once done.
      • rxClose

        public io.reactivex.Completable rxClose()
        Closes the DatagramSocket implementation asynchronous and notifies the handler once done.
        Returns:
      • listenMulticastGroup

        public DatagramSocket listenMulticastGroup​(String multicastAddress,
                                                   Handler<AsyncResult<Void>> 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
        Returns:
        a reference to this, so the API can be used fluently
      • listenMulticastGroup

        public DatagramSocket listenMulticastGroup​(String multicastAddress)
        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
        Returns:
        a reference to this, so the API can be used fluently
      • rxListenMulticastGroup

        public io.reactivex.Completable rxListenMulticastGroup​(String multicastAddress)
        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
        Returns:
        a reference to this, so the API can be used fluently
      • listenMulticastGroup

        public DatagramSocket listenMulticastGroup​(String multicastAddress,
                                                   String networkInterface,
                                                   String source,
                                                   Handler<AsyncResult<Void>> 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
        Returns:
        a reference to this, so the API can be used fluently
      • listenMulticastGroup

        public DatagramSocket listenMulticastGroup​(String multicastAddress,
                                                   String networkInterface,
                                                   String source)
        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
        Returns:
        a reference to this, so the API can be used fluently
      • rxListenMulticastGroup

        public io.reactivex.Completable rxListenMulticastGroup​(String multicastAddress,
                                                               String networkInterface,
                                                               String source)
        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
        Returns:
        a reference to this, so the API can be used fluently
      • unlistenMulticastGroup

        public DatagramSocket unlistenMulticastGroup​(String multicastAddress,
                                                     Handler<AsyncResult<Void>> 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
        Returns:
        a reference to this, so the API can be used fluently
      • unlistenMulticastGroup

        public DatagramSocket unlistenMulticastGroup​(String multicastAddress)
        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
        Returns:
        a reference to this, so the API can be used fluently
      • rxUnlistenMulticastGroup

        public io.reactivex.Completable rxUnlistenMulticastGroup​(String multicastAddress)
        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
        Returns:
        a reference to this, so the API can be used fluently
      • unlistenMulticastGroup

        public DatagramSocket unlistenMulticastGroup​(String multicastAddress,
                                                     String networkInterface,
                                                     String source,
                                                     Handler<AsyncResult<Void>> 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
        Returns:
        a reference to this, so the API can be used fluently
      • unlistenMulticastGroup

        public DatagramSocket unlistenMulticastGroup​(String multicastAddress,
                                                     String networkInterface,
                                                     String source)
        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
        Returns:
        a reference to this, so the API can be used fluently
      • rxUnlistenMulticastGroup

        public io.reactivex.Completable rxUnlistenMulticastGroup​(String multicastAddress,
                                                                 String networkInterface,
                                                                 String source)
        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
        Returns:
        a reference to this, so the API can be used fluently
      • blockMulticastGroup

        public DatagramSocket blockMulticastGroup​(String multicastAddress,
                                                  String sourceToBlock,
                                                  Handler<AsyncResult<Void>> 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
        Returns:
        a reference to this, so the API can be used fluently
      • blockMulticastGroup

        public DatagramSocket blockMulticastGroup​(String multicastAddress,
                                                  String sourceToBlock)
        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.
        Returns:
        a reference to this, so the API can be used fluently
      • rxBlockMulticastGroup

        public io.reactivex.Completable rxBlockMulticastGroup​(String multicastAddress,
                                                              String sourceToBlock)
        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.
        Returns:
        a reference to this, so the API can be used fluently
      • blockMulticastGroup

        public DatagramSocket blockMulticastGroup​(String multicastAddress,
                                                  String networkInterface,
                                                  String sourceToBlock,
                                                  Handler<AsyncResult<Void>> 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
        Returns:
        a reference to this, so the API can be used fluently
      • blockMulticastGroup

        public DatagramSocket blockMulticastGroup​(String multicastAddress,
                                                  String networkInterface,
                                                  String sourceToBlock)
        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.
        Returns:
        a reference to this, so the API can be used fluently
      • rxBlockMulticastGroup

        public io.reactivex.Completable rxBlockMulticastGroup​(String multicastAddress,
                                                              String networkInterface,
                                                              String sourceToBlock)
        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.
        Returns:
        a reference to this, so the API can be used fluently
      • listen

        public DatagramSocket listen​(int port,
                                     String host,
                                     Handler<AsyncResult<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
        Returns:
        a reference to this, so the API can be used fluently
      • listen

        public 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 reference to this, so the API can be used fluently
      • rxListen

        public io.reactivex.Single<DatagramSocket> rxListen​(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 reference to this, so the API can be used fluently
      • pause

        @Deprecated
        public DatagramSocket pause()
        Deprecated.
        Description copied from interface: ReadStream
        Pause the ReadStream, it sets the buffer in fetch mode and clears the actual demand.

        While it's paused, no data will be sent to the data handler.

        Specified by:
        pause in interface ReadStream<DatagramPacket>
        Returns:
      • fetch

        @Deprecated
        public DatagramSocket fetch​(long amount)
        Deprecated.
        Description copied from interface: ReadStream
        Fetch the specified amount of elements. If the ReadStream has been paused, reading will recommence with the specified amount of items, otherwise the specified amount will be added to the current stream demand.
        Specified by:
        fetch in interface ReadStream<DatagramPacket>
        Parameters:
        amount -
        Returns: