Class DatagramSocket
- java.lang.Object
-
- io.vertx.mutiny.core.datagram.DatagramSocket
-
- All Implemented Interfaces:
Measured,ReadStream<DatagramPacket>,StreamBase
public class DatagramSocket extends Object implements ReadStream<DatagramPacket>, Measured
A datagram socket can be used to sendDatagramPacket's to remote datagram servers and receiveDatagramPackets .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 theoriginalnon Mutiny-ified interface using Vert.x codegen.
-
-
Field Summary
Fields Modifier and Type Field Description static TypeArg<DatagramSocket>__TYPE_ARG
-
Constructor Summary
Constructors Constructor Description DatagramSocket(io.vertx.core.datagram.DatagramSocket delegate)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description io.smallrye.mutiny.Uni<DatagramSocket>blockMulticastGroup(String multicastAddress, String sourceToBlock)Block the given address for the given multicast address and notifies the once the operation completes.io.smallrye.mutiny.Uni<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.DatagramSocketblockMulticastGroupAndAwait(String multicastAddress, String sourceToBlock)Blocking variant ofblockMulticastGroup(String,String).DatagramSocketblockMulticastGroupAndAwait(String multicastAddress, String networkInterface, String sourceToBlock)Blocking variant ofblockMulticastGroup(String,String,String).io.smallrye.mutiny.Uni<Void>close()Closes theDatagramSocketimplementation asynchronous and notifies the handler once done.VoidcloseAndAwait()Blocking variant ofclose().voidcloseAndForget()Variant ofclose()that ignores the result of the operation.DatagramSocketendHandler(Consumer<Void> endHandler)booleanequals(Object o)DatagramSocketexceptionHandler(Consumer<Throwable> handler)DatagramSocketfetch(long amount)io.vertx.core.datagram.DatagramSocketgetDelegate()DatagramSockethandler(Consumer<DatagramPacket> handler)inthashCode()booleanisMetricsEnabled()io.smallrye.mutiny.Uni<DatagramSocket>listen(int port, String host)Start listening on the given port and host.DatagramSocketlistenAndAwait(int port, String host)Blocking variant oflisten(int,String).io.smallrye.mutiny.Uni<DatagramSocket>listenMulticastGroup(String multicastAddress)Joins a multicast group and listens for packets send to it.io.smallrye.mutiny.Uni<DatagramSocket>listenMulticastGroup(String multicastAddress, String networkInterface, String source)Joins a multicast group and listens for packets send to it on the given network interface.DatagramSocketlistenMulticastGroupAndAwait(String multicastAddress)Blocking variant oflistenMulticastGroup(String).DatagramSocketlistenMulticastGroupAndAwait(String multicastAddress, String networkInterface, String source)Blocking variant oflistenMulticastGroup(String,String,String).SocketAddresslocalAddress()static DatagramSocketnewInstance(io.vertx.core.datagram.DatagramSocket arg)DatagramSocketpause()Pipe<DatagramPacket>pipe()io.smallrye.mutiny.Uni<Void>pipeTo(WriteStream<DatagramPacket> dst)Pipe thisReadStreamto theWriteStream.VoidpipeToAndAwait(WriteStream<DatagramPacket> dst)Blocking variant ofio.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStream.) voidpipeToAndForget(WriteStream<DatagramPacket> dst)Variant ofio.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStreamthat ignores the result of the operation.) DatagramSocketresume()io.smallrye.mutiny.Uni<DatagramSocket>send(Buffer packet, int port, String host)Write the givenBufferto theSocketAddress.io.smallrye.mutiny.Uni<DatagramSocket>send(String str, int port, String host)Write the givenStringto theSocketAddressusing UTF8 encoding.io.smallrye.mutiny.Uni<DatagramSocket>send(String str, String enc, int port, String host)Write the givenStringto theSocketAddressusing the given encoding.DatagramSocketsendAndAwait(Buffer packet, int port, String host)Blocking variant ofsend(io.vertx.mutiny.core.buffer.Buffer,int,String).DatagramSocketsendAndAwait(String str, int port, String host)Blocking variant ofsend(String,int,String).DatagramSocketsendAndAwait(String str, String enc, int port, String host)Blocking variant ofsend(String,String,int,String).WriteStream<Buffer>sender(int port, String host)Iterable<DatagramPacket>toBlockingIterable()Stream<DatagramPacket>toBlockingStream()io.smallrye.mutiny.Multi<DatagramPacket>toMulti()StringtoString()io.smallrye.mutiny.Uni<DatagramSocket>unlistenMulticastGroup(String multicastAddress)Leaves a multicast group and stops listening for packets send to it.io.smallrye.mutiny.Uni<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.DatagramSocketunlistenMulticastGroupAndAwait(String multicastAddress)Blocking variant ofunlistenMulticastGroup(String).DatagramSocketunlistenMulticastGroupAndAwait(String multicastAddress, String networkInterface, String source)Blocking variant ofunlistenMulticastGroup(String,String,String).
-
-
-
Field Detail
-
__TYPE_ARG
public static final TypeArg<DatagramSocket> __TYPE_ARG
-
-
Method Detail
-
getDelegate
public io.vertx.core.datagram.DatagramSocket getDelegate()
- Specified by:
getDelegatein interfaceMeasured- Specified by:
getDelegatein interfaceReadStream<DatagramPacket>- Specified by:
getDelegatein interfaceStreamBase
-
isMetricsEnabled
public boolean isMetricsEnabled()
- Specified by:
isMetricsEnabledin interfaceMeasured- Returns:
trueif metrics are enabled
-
pipe
public Pipe<DatagramPacket> pipe()
- Specified by:
pipein interfaceReadStream<DatagramPacket>- Returns:
- a pipe
-
pipeTo
public io.smallrye.mutiny.Uni<Void> pipeTo(WriteStream<DatagramPacket> dst)
Pipe thisReadStreamto theWriteStream.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
handlerwill be called with the result.Unlike the bare Vert.x variant, this method returns a
Uni. Don't forget to subscribe on it to trigger the operation.- Specified by:
pipeToin interfaceReadStream<DatagramPacket>- Parameters:
dst- the destination write stream- Returns:
- the
unifiring the result of the operation when completed, or a failure if the operation failed.
-
pipeToAndAwait
public Void pipeToAndAwait(WriteStream<DatagramPacket> dst)
Blocking variant ofio.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStream.) This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Specified by:
pipeToAndAwaitin interfaceReadStream<DatagramPacket>- Parameters:
dst- the destination write stream- Returns:
- the Void instance produced by the operation
-
send
public io.smallrye.mutiny.Uni<DatagramSocket> send(Buffer packet, int port, String host)
Write the givenBufferto theSocketAddress. TheHandlerwill be notified once the write completes.Unlike the bare Vert.x variant, this method returns a
Uni. Don't forget to subscribe on it to trigger the operation.- Parameters:
packet- theBufferto writeport- the host port of the remote peerhost- the host address of the remote peer- Returns:
- a reference to this, so the API can be used fluently
-
sendAndAwait
public DatagramSocket sendAndAwait(Buffer packet, int port, String host)
Blocking variant ofsend(io.vertx.mutiny.core.buffer.Buffer,int,String).This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Parameters:
packet- theBufferto writeport- the host port of the remote peerhost- 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)
- Parameters:
port- the port of the remote peerhost- the host address of the remote peer- Returns:
- the write stream for sending packets
-
send
public io.smallrye.mutiny.Uni<DatagramSocket> send(String str, int port, String host)
Write the givenStringto theSocketAddressusing UTF8 encoding. The will be notified once the write completes.Unlike the bare Vert.x variant, this method returns a
Uni. Don't forget to subscribe on it to trigger the operation.- Parameters:
str- theStringto writeport- the host port of the remote peerhost- the host address of the remote peer- Returns:
- a reference to this, so the API can be used fluently
-
sendAndAwait
public DatagramSocket sendAndAwait(String str, int port, String host)
Blocking variant ofsend(String,int,String).This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Parameters:
str- theStringto writeport- the host port of the remote peerhost- the host address of the remote peer- Returns:
- a reference to this, so the API can be used fluently
-
send
public io.smallrye.mutiny.Uni<DatagramSocket> send(String str, String enc, int port, String host)
Write the givenStringto theSocketAddressusing the given encoding. The will be notified once the write completes.Unlike the bare Vert.x variant, this method returns a
Uni. Don't forget to subscribe on it to trigger the operation.- Parameters:
str- theStringto writeenc- the charset used for encodingport- the host port of the remote peerhost- the host address of the remote peer- Returns:
- a reference to this, so the API can be used fluently
-
sendAndAwait
public DatagramSocket sendAndAwait(String str, String enc, int port, String host)
Blocking variant ofsend(String,String,int,String).This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Parameters:
str- theStringto writeenc- the charset used for encodingport- the host port of the remote peerhost- the host address of the remote peer- Returns:
- a reference to this, so the API can be used fluently
-
close
public io.smallrye.mutiny.Uni<Void> close()
Closes theDatagramSocketimplementation asynchronous and notifies the handler once done.Unlike the bare Vert.x variant, this method returns a
Uni. Don't forget to subscribe on it to trigger the operation.- Returns:
- the
unifiring the result of the operation when completed, or a failure if the operation failed.
-
closeAndAwait
public Void closeAndAwait()
Blocking variant ofclose().This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Returns:
- the Void instance produced by the operation
-
localAddress
public SocketAddress localAddress()
- Returns:
- the socket address
-
listenMulticastGroup
public io.smallrye.mutiny.Uni<DatagramSocket> listenMulticastGroup(String multicastAddress)
Joins a multicast group and listens for packets send to it. The is notified once the operation completes.Unlike the bare Vert.x variant, this method returns a
Uni. Don't forget to subscribe on it to trigger the operation.- Parameters:
multicastAddress- the address of the multicast group to join- Returns:
- a reference to this, so the API can be used fluently
-
listenMulticastGroupAndAwait
public DatagramSocket listenMulticastGroupAndAwait(String multicastAddress)
Blocking variant oflistenMulticastGroup(String).This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Parameters:
multicastAddress- the address of the multicast group to join- Returns:
- a reference to this, so the API can be used fluently
-
listenMulticastGroup
public io.smallrye.mutiny.Uni<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.Unlike the bare Vert.x variant, this method returns a
Uni. Don't forget to subscribe on it to trigger the operation.- Parameters:
multicastAddress- the address of the multicast group to joinnetworkInterface- 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
-
listenMulticastGroupAndAwait
public DatagramSocket listenMulticastGroupAndAwait(String multicastAddress, String networkInterface, String source)
Blocking variant oflistenMulticastGroup(String,String,String).This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Parameters:
multicastAddress- the address of the multicast group to joinnetworkInterface- 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 io.smallrye.mutiny.Uni<DatagramSocket> unlistenMulticastGroup(String multicastAddress)
Leaves a multicast group and stops listening for packets send to it. The is notified once the operation completes.Unlike the bare Vert.x variant, this method returns a
Uni. Don't forget to subscribe on it to trigger the operation.- Parameters:
multicastAddress- the address of the multicast group to leave- Returns:
- a reference to this, so the API can be used fluently
-
unlistenMulticastGroupAndAwait
public DatagramSocket unlistenMulticastGroupAndAwait(String multicastAddress)
Blocking variant ofunlistenMulticastGroup(String).This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Parameters:
multicastAddress- the address of the multicast group to leave- Returns:
- a reference to this, so the API can be used fluently
-
unlistenMulticastGroup
public io.smallrye.mutiny.Uni<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.Unlike the bare Vert.x variant, this method returns a
Uni. Don't forget to subscribe on it to trigger the operation.- Parameters:
multicastAddress- the address of the multicast group to joinnetworkInterface- 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
-
unlistenMulticastGroupAndAwait
public DatagramSocket unlistenMulticastGroupAndAwait(String multicastAddress, String networkInterface, String source)
Blocking variant ofunlistenMulticastGroup(String,String,String).This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Parameters:
multicastAddress- the address of the multicast group to joinnetworkInterface- 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 io.smallrye.mutiny.Uni<DatagramSocket> blockMulticastGroup(String multicastAddress, String sourceToBlock)
Block the given address for the given multicast address and notifies the once the operation completes.Unlike the bare Vert.x variant, this method returns a
Uni. Don't forget to subscribe on it to trigger the operation.- Parameters:
multicastAddress- the address for which you want to block the source addresssourceToBlock- 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
-
blockMulticastGroupAndAwait
public DatagramSocket blockMulticastGroupAndAwait(String multicastAddress, String sourceToBlock)
Blocking variant ofblockMulticastGroup(String,String).This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Parameters:
multicastAddress- the address for which you want to block the source addresssourceToBlock- 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 io.smallrye.mutiny.Uni<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.Unlike the bare Vert.x variant, this method returns a
Uni. Don't forget to subscribe on it to trigger the operation.- Parameters:
multicastAddress- the address for which you want to block the source addressnetworkInterface- 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
-
blockMulticastGroupAndAwait
public DatagramSocket blockMulticastGroupAndAwait(String multicastAddress, String networkInterface, String sourceToBlock)
Blocking variant ofblockMulticastGroup(String,String,String).This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Parameters:
multicastAddress- the address for which you want to block the source addressnetworkInterface- 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 io.smallrye.mutiny.Uni<DatagramSocket> listen(int port, String host)
Start listening on the given port and host. The handler will be called when the socket is listening.Unlike the bare Vert.x variant, this method returns a
Uni. Don't forget to subscribe on it to trigger the operation.- Parameters:
port- the port to listen onhost- the host to listen on- Returns:
- a reference to this, so the API can be used fluently
-
listenAndAwait
public DatagramSocket listenAndAwait(int port, String host)
Blocking variant oflisten(int,String).This method waits for the completion of the underlying asynchronous operation. If the operation completes successfully, the result is returned, otherwise the failure is thrown (potentially wrapped in a RuntimeException).
- Parameters:
port- the port to listen onhost- the host to listen on- Returns:
- a reference to this, so the API can be used fluently
-
pause
public DatagramSocket pause()
- Specified by:
pausein interfaceReadStream<DatagramPacket>- Returns:
- a reference to this, so the API can be used fluently
-
resume
public DatagramSocket resume()
- Specified by:
resumein interfaceReadStream<DatagramPacket>- Returns:
- a reference to this, so the API can be used fluently
-
fetch
public DatagramSocket fetch(long amount)
- Specified by:
fetchin interfaceReadStream<DatagramPacket>- Returns:
- a reference to this, so the API can be used fluently
-
endHandler
public DatagramSocket endHandler(Consumer<Void> endHandler)
- Specified by:
endHandlerin interfaceReadStream<DatagramPacket>- Returns:
- a reference to this, so the API can be used fluently
-
handler
public DatagramSocket handler(Consumer<DatagramPacket> handler)
- Specified by:
handlerin interfaceReadStream<DatagramPacket>- Returns:
- a reference to this, so the API can be used fluently
-
exceptionHandler
public DatagramSocket exceptionHandler(Consumer<Throwable> handler)
- Specified by:
exceptionHandlerin interfaceReadStream<DatagramPacket>- Specified by:
exceptionHandlerin interfaceStreamBase- Parameters:
handler- the exception handler- Returns:
- a reference to this, so the API can be used fluently
-
pipeToAndForget
public void pipeToAndForget(WriteStream<DatagramPacket> dst)
Variant ofio.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStreamthat ignores the result of the operation.) This method subscribes on the result of
io.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStream, but discards the outcome (item or failure). This method is useful to trigger the asynchronous operation from) io.vertx.mutiny.core.streams.ReadStream#pipeTo(io.vertx.mutiny.core.streams.WriteStreambut you don't need to compose it with other operations.) - Parameters:
dst-
-
closeAndForget
public void closeAndForget()
-
toMulti
public io.smallrye.mutiny.Multi<DatagramPacket> toMulti()
- Specified by:
toMultiin interfaceReadStream<DatagramPacket>
-
toBlockingIterable
public Iterable<DatagramPacket> toBlockingIterable()
-
toBlockingStream
public Stream<DatagramPacket> toBlockingStream()
-
newInstance
public static DatagramSocket newInstance(io.vertx.core.datagram.DatagramSocket arg)
-
-