Top Description Methods
io.vertx.core.datagram

public Interface DatagramSocket

extends ReadStream<DatagramPacket>, Measured
Known Direct Implementers
io.vertx.core.datagram.impl.DatagramSocketImpl
Annotations
@VertxGen
Imports
io.vertx.codegen.annotations.Nullable, .CacheReturn, .Fluent, .VertxGen, io.vertx.core.AsyncResult, .Future, .Handler, io.vertx.core.buffer.Buffer, io.vertx.core.metrics.Measured, io.vertx.core.net.SocketAddress, io.vertx.core.streams.ReadStream, .WriteStream

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 Summary

Modifier and TypeMethod and Description
public DatagramSocket

Returns:

a reference to this, so the API can be used fluently
blockMulticastGroup
(String
the address for which you want to block the source address
multicastAddress
,
String
the source address which should be blocked. You will not receive an multicast packets for it anymore.
sourceToBlock
,
Handler<AsyncResult<Void>>
the handler to notify once the operation completes
handler
)

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

public Future<Void>
blockMulticastGroup(String multicastAddress, String sourceToBlock)

Like blockMulticastGroup(String, String, Handler) but returns a Future of the asynchronous result

public DatagramSocket

Returns:

a reference to this, so the API can be used fluently
blockMulticastGroup
(String
the address for which you want to block the source address
multicastAddress
,
String
the network interface on which the blocking should occur.
networkInterface
,
String
the source address which should be blocked. You will not receive an multicast packets for it anymore.
sourceToBlock
,
Handler<AsyncResult<Void>>
the handler to notify once the operation completes
handler
)

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

public Future<Void>
blockMulticastGroup(String multicastAddress, String networkInterface, String sourceToBlock)

Like blockMulticastGroup(String, String, String, Handler) but returns a Future of the asynchronous result

public void
close(Handler<AsyncResult<Void>>
the handler to notify once complete
handler
)

Closes the io.vertx.core.datagram.DatagramSocket implementation asynchronous and notifies the handler once done.

public Future<Void>
public DatagramSocket
endHandler(Handler<Void> endHandler)
Deprecated removed in Vert.x 5

public DatagramSocket
public DatagramSocket
fetch(long amount)

Redeclares io.vertx.core.streams.ReadStream.fetch.

Deprecated no replacement for back-pressure, instead ignore the packet or buffer it somewhere

Fetch the specified amount of elements.

public DatagramSocket
public DatagramSocket

Returns:

a reference to this, so the API can be used fluently
listen
(int
the port to listen on
port
,
String
the host to listen on
host
,
Handler<AsyncResult<DatagramSocket>>
the handler will be called when listening
handler
)

Start listening on the given port and host.

public Future<DatagramSocket>
listen(int port, String host)

Like listen(int, String, Handler) but returns a Future of the asynchronous result

public DatagramSocket

Returns:

a reference to this, so the API can be used fluently
listenMulticastGroup
(String
the address of the multicast group to join
multicastAddress
,
Handler<AsyncResult<Void>>
then handler to notify once the operation completes
handler
)

Joins a multicast group and listens for packets send to it.

public Future<Void>
listenMulticastGroup(String multicastAddress)

Like listenMulticastGroup(String, Handler) but returns a Future of the asynchronous result

public DatagramSocket

Returns:

a reference to this, so the API can be used fluently
listenMulticastGroup
(String
the address of the multicast group to join
multicastAddress
,
String
the network interface on which to listen for packets.
networkInterface
,
@Nullable String
the address of the source for which we will listen for multicast packets
source
,
Handler<AsyncResult<Void>>
then handler to notify once the operation completes
handler
)

Joins a multicast group and listens for packets send to it on the given network interface.

public Future<Void>
listenMulticastGroup(String multicastAddress, String networkInterface, @Nullable String source)

Like listenMulticastGroup(String, String, String, Handler) but returns a Future of the asynchronous result

public SocketAddress

Returns:

the socket address
localAddress
()

Return the io.vertx.core.net.SocketAddress to which this io.vertx.core.datagram.DatagramSocket is bound.

public DatagramSocket
pause()

Redeclares io.vertx.core.streams.ReadStream.pause.

Deprecated no replacement for back-pressure, instead ignore the packet or buffer it somewhere

Pause the ReadStream, it sets the buffer in fetch mode and clears the actual demand.

public DatagramSocket
resume()

Redeclares io.vertx.core.streams.ReadStream.resume.

Deprecated no replacement for back-pressure, instead ignore the packet or buffer it somewhere

Resume reading, and sets the buffer in flowing mode.

public DatagramSocket

Returns:

a reference to this, so the API can be used fluently
send
(Buffer packet, int
the host port of the remote peer
port
,
String
the host address of the remote peer
host
,
Handler<AsyncResult<Void>>
the io.vertx.core.Handler to notify once the write completes.
handler
)
References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Write the given io.vertx.core.buffer.Buffer to the io.vertx.core.net.SocketAddress.

public Future<Void>
send(Buffer packet, int port, String host)
References Deprecated Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

Like send(Buffer, int, String, Handler) but returns a Future of the asynchronous result

public DatagramSocket

Returns:

a reference to this, so the API can be used fluently
send
(String
the String to write
str
,
int
the host port of the remote peer
port
,
String
the host address of the remote peer
host
,
Handler<AsyncResult<Void>>
the io.vertx.core.Handler to notify once the write completes.
handler
)

Write the given String to the io.vertx.core.net.SocketAddress using UTF8 encoding.

public Future<Void>
send(String str, int port, String host)

Like send(String, int, String, Handler) but returns a Future of the asynchronous result

public DatagramSocket

Returns:

a reference to this, so the API can be used fluently
send
(String
the String to write
str
,
String
the charset used for encoding
enc
,
int
the host port of the remote peer
port
,
String
the host address of the remote peer
host
,
Handler<AsyncResult<Void>>
the io.vertx.core.Handler to notify once the write completes.
handler
)

Write the given String to the io.vertx.core.net.SocketAddress using the given encoding.

public Future<Void>
send(String str, String enc, int port, String host)

Like send(String, String, int, String, Handler) but returns a Future of the asynchronous result

public WriteStream<Buffer>

Returns:

the write stream for sending packets
sender
(int
the port of the remote peer
port
,
String
the host address of the remote peer
host
)

Returns a WriteStream<Buffer> able to send Buffer to the io.vertx.core.net.SocketAddress.

public DatagramSocket

Returns:

a reference to this, so the API can be used fluently
unlistenMulticastGroup
(String
the address of the multicast group to leave
multicastAddress
,
Handler<AsyncResult<Void>>
then handler to notify once the operation completes
handler
)

Leaves a multicast group and stops listening for packets send to it.

public Future<Void>
unlistenMulticastGroup(String multicastAddress)

Like unlistenMulticastGroup(String, Handler) but returns a Future of the asynchronous result

public DatagramSocket

Returns:

a reference to this, so the API can be used fluently
unlistenMulticastGroup
(String
the address of the multicast group to join
multicastAddress
,
String
the network interface on which to listen for packets.
networkInterface
,
@Nullable String
the address of the source for which we will listen for multicast packets
source
,
Handler<AsyncResult<Void>>
the handler to notify once the operation completes
handler
)

Leaves a multicast group and stops listening for packets send to it on the given network interface.

public Future<Void>
unlistenMulticastGroup(String multicastAddress, String networkInterface, @Nullable String source)

Like unlistenMulticastGroup(String, String, String, Handler) but returns a Future of the asynchronous result

Inherited from io.vertx.core.metrics.Measured:
isMetricsEnabled
Inherited from io.vertx.core.streams.ReadStream:
collectendHandlerexceptionHandlerhandlerpipepipeTopipeTo

Method Detail

blockMulticastGroupback to summary
public DatagramSocket blockMulticastGroup(String multicastAddress, String sourceToBlock, Handler<AsyncResult<Void>> handler)

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

Parameters
multicastAddress:String

the address for which you want to block the source address

sourceToBlock:String

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

handler:Handler<AsyncResult<Void>>

the handler to notify once the operation completes

Returns:DatagramSocket

a reference to this, so the API can be used fluently

Annotations
@Fluent
blockMulticastGroupback to summary
public Future<Void> blockMulticastGroup(String multicastAddress, String sourceToBlock)

Like blockMulticastGroup(String, String, Handler) but returns a Future of the asynchronous result

blockMulticastGroupback to summary
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 Handler once the operation completes.

Parameters
multicastAddress:String

the address for which you want to block the source address

networkInterface:String

the network interface on which the blocking should occur.

sourceToBlock:String

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

handler:Handler<AsyncResult<Void>>

the handler to notify once the operation completes

Returns:DatagramSocket

a reference to this, so the API can be used fluently

Annotations
@Fluent
blockMulticastGroupback to summary
public Future<Void> blockMulticastGroup(String multicastAddress, String networkInterface, String sourceToBlock)

Like blockMulticastGroup(String, String, String, Handler) but returns a Future of the asynchronous result

closeback to summary
public void close(Handler<AsyncResult<Void>> handler)

Closes the io.vertx.core.datagram.DatagramSocket implementation asynchronous and notifies the handler once done.

Parameters
handler:Handler<AsyncResult<Void>>

the handler to notify once complete

closeback to summary
public Future<Void> close()

Closes the io.vertx.core.datagram.DatagramSocket. The close itself is asynchronous.

endHandlerback to summary
public DatagramSocket endHandler(Handler<Void> endHandler)

Deprecated

removed in Vert.x 5

Annotations
@Deprecated
@Override
exceptionHandlerback to summary
public DatagramSocket exceptionHandler(Handler<Throwable> handler)
Annotations
@Override
fetchback to summary
public DatagramSocket fetch(long amount)

Redeclares io.vertx.core.streams.ReadStream.fetch.

Doc from io.vertx.core.streams.ReadStream.fetch.

Deprecated

no replacement for back-pressure, instead ignore the packet or buffer it somewhere

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.

Returns:DatagramSocket

a reference to this, so the API can be used fluently

Annotations
@Deprecated
@Override
handlerback to summary
public DatagramSocket handler(Handler<DatagramPacket> handler)
Annotations
@Override
listenback to summary
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:int

the port to listen on

host:String

the host to listen on

handler:Handler<AsyncResult<DatagramSocket>>

the handler will be called when listening

Returns:DatagramSocket

a reference to this, so the API can be used fluently

Annotations
@Fluent
listenback to summary
public Future<DatagramSocket> listen(int port, String host)

Like listen(int, String, Handler) but returns a Future of the asynchronous result

listenMulticastGroupback to summary
public DatagramSocket listenMulticastGroup(String multicastAddress, Handler<AsyncResult<Void>> handler)

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

Parameters
multicastAddress:String

the address of the multicast group to join

handler:Handler<AsyncResult<Void>>

then handler to notify once the operation completes

Returns:DatagramSocket

a reference to this, so the API can be used fluently

Annotations
@Fluent
listenMulticastGroupback to summary
public Future<Void> listenMulticastGroup(String multicastAddress)

Like listenMulticastGroup(String, Handler) but returns a Future of the asynchronous result

listenMulticastGroupback to summary
public DatagramSocket listenMulticastGroup(String multicastAddress, String networkInterface, @Nullable String source, Handler<AsyncResult<Void>> handler)

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

Parameters
multicastAddress:String

the address of the multicast group to join

networkInterface:String

the network interface on which to listen for packets.

source:@Nullable String

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

handler:Handler<AsyncResult<Void>>

then handler to notify once the operation completes

Returns:DatagramSocket

a reference to this, so the API can be used fluently

Annotations
@Fluent
listenMulticastGroupback to summary
public Future<Void> listenMulticastGroup(String multicastAddress, String networkInterface, @Nullable String source)

Like listenMulticastGroup(String, String, String, Handler) but returns a Future of the asynchronous result

localAddressback to summary
public SocketAddress localAddress()

Return the io.vertx.core.net.SocketAddress to which this io.vertx.core.datagram.DatagramSocket is bound.

Returns:SocketAddress

the socket address

Annotations
@CacheReturn
pauseback to summary
public DatagramSocket pause()

Redeclares io.vertx.core.streams.ReadStream.pause.

Doc from io.vertx.core.streams.ReadStream.pause.

Deprecated

no replacement for back-pressure, instead ignore the packet or buffer it somewhere

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.

Returns:DatagramSocket

a reference to this, so the API can be used fluently

Annotations
@Deprecated
@Override
resumeback to summary
public DatagramSocket resume()

Redeclares io.vertx.core.streams.ReadStream.resume.

Doc from io.vertx.core.streams.ReadStream.resume.

Deprecated

no replacement for back-pressure, instead ignore the packet or buffer it somewhere

Resume reading, and sets the buffer in flowing mode.

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

Returns:DatagramSocket

a reference to this, so the API can be used fluently

Annotations
@Deprecated
@Override
sendback to summary
public DatagramSocket send(Buffer packet, int port, String host, Handler<AsyncResult<Void>> handler)

References Deprecated

Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

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

Parameters
packet:Buffer

the io.vertx.core.buffer.Buffer to write

port:int

the host port of the remote peer

host:String

the host address of the remote peer

handler:Handler<AsyncResult<Void>>

the io.vertx.core.Handler to notify once the write completes.

Returns:DatagramSocket

a reference to this, so the API can be used fluently

Annotations
@Fluent
sendback to summary
public Future<Void> send(Buffer packet, int port, String host)

References Deprecated

Buffer is deprecated or references (maybe indirectly) at least one deprecated element.

See corresponding docs for further information.

Like send(Buffer, int, String, Handler) but returns a Future of the asynchronous result

sendback to summary
public DatagramSocket send(String str, int port, String host, Handler<AsyncResult<Void>> handler)

Write the given String to the io.vertx.core.net.SocketAddress using UTF8 encoding. The Handler will be notified once the write completes.

Parameters
str:String

the String to write

port:int

the host port of the remote peer

host:String

the host address of the remote peer

handler:Handler<AsyncResult<Void>>

the io.vertx.core.Handler to notify once the write completes.

Returns:DatagramSocket

a reference to this, so the API can be used fluently

Annotations
@Fluent
sendback to summary
public Future<Void> send(String str, int port, String host)

Like send(String, int, String, Handler) but returns a Future of the asynchronous result

sendback to summary
public DatagramSocket send(String str, String enc, int port, String host, Handler<AsyncResult<Void>> handler)

Write the given String to the io.vertx.core.net.SocketAddress using the given encoding. The Handler will be notified once the write completes.

Parameters
str:String

the String to write

enc:String

the charset used for encoding

port:int

the host port of the remote peer

host:String

the host address of the remote peer

handler:Handler<AsyncResult<Void>>

the io.vertx.core.Handler to notify once the write completes.

Returns:DatagramSocket

a reference to this, so the API can be used fluently

Annotations
@Fluent
sendback to summary
public Future<Void> send(String str, String enc, int port, String host)

Like send(String, String, int, String, Handler) but returns a Future of the asynchronous result

senderback to summary
public WriteStream<Buffer> sender(int port, String host)

Returns a WriteStream<Buffer> able to send Buffer to the io.vertx.core.net.SocketAddress.

Parameters
port:int

the port of the remote peer

host:String

the host address of the remote peer

Returns:WriteStream<Buffer>

the write stream for sending packets

unlistenMulticastGroupback to summary
public DatagramSocket unlistenMulticastGroup(String multicastAddress, Handler<AsyncResult<Void>> handler)

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

Parameters
multicastAddress:String

the address of the multicast group to leave

handler:Handler<AsyncResult<Void>>

then handler to notify once the operation completes

Returns:DatagramSocket

a reference to this, so the API can be used fluently

Annotations
@Fluent
unlistenMulticastGroupback to summary
public Future<Void> unlistenMulticastGroup(String multicastAddress)

Like unlistenMulticastGroup(String, Handler) but returns a Future of the asynchronous result

unlistenMulticastGroupback to summary
public DatagramSocket unlistenMulticastGroup(String multicastAddress, String networkInterface, @Nullable String source, Handler<AsyncResult<Void>> handler)

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

Parameters
multicastAddress:String

the address of the multicast group to join

networkInterface:String

the network interface on which to listen for packets.

source:@Nullable String

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

handler:Handler<AsyncResult<Void>>

the handler to notify once the operation completes

Returns:DatagramSocket

a reference to this, so the API can be used fluently

Annotations
@Fluent
unlistenMulticastGroupback to summary
public Future<Void> unlistenMulticastGroup(String multicastAddress, String networkInterface, @Nullable String source)

Like unlistenMulticastGroup(String, String, String, Handler) but returns a Future of the asynchronous result