Package io.vertx.core.datagram
Interface DatagramSocket
-
- All Superinterfaces:
Measured
public interface DatagramSocket extends Measured
A datagram socket can be used to sendDatagramPacket
's to remote datagram servers and receiveDatagramPacket
s .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
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Future<Void>
blockMulticastGroup(String multicastAddress, String sourceToBlock)
Block the given address for the given multicast address and notifies theHandler
once the operation completes.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 theHandler
once the operation completes.Future<Void>
close()
Closes theDatagramSocket
implementation asynchronous and notifies the handler once done.DatagramSocket
exceptionHandler(Handler<Throwable> handler)
DatagramSocket
handler(Handler<DatagramPacket> handler)
Future<DatagramSocket>
listen(int port, String host)
Start listening on the given port and host.Future<Void>
listenMulticastGroup(String multicastAddress)
Joins a multicast group and listens for packets send to it.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.SocketAddress
localAddress()
Return theSocketAddress
to which thisDatagramSocket
is bound.Future<Void>
send(Buffer packet, int port, String host)
Write the givenBuffer
to theSocketAddress
.Future<Void>
send(String str, int port, String host)
Write the givenString
to theSocketAddress
using UTF8 encoding.Future<Void>
send(String str, String enc, int port, String host)
Write the givenString
to theSocketAddress
using the given encoding.WriteStream<Buffer>
sender(int port, String host)
Future<Void>
unlistenMulticastGroup(String multicastAddress)
Leaves a multicast group and stops listening for packets send to it.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.-
Methods inherited from interface io.vertx.core.metrics.Measured
isMetricsEnabled
-
-
-
-
Method Detail
-
send
Future<Void> send(Buffer packet, int port, String host)
Write the givenBuffer
to theSocketAddress
.- Parameters:
packet
- theBuffer
to writeport
- the host port of the remote peerhost
- the host address of the remote peer- Returns:
- a future notified once the write completes.
-
sender
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
Future<Void> send(String str, int port, String host)
Write the givenString
to theSocketAddress
using UTF8 encoding.- Parameters:
str
- theString
to writeport
- the host port of the remote peerhost
- 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 givenString
to theSocketAddress
using the given encoding.- Parameters:
str
- theString
to writeenc
- the charset used for encodingport
- the host port of the remote peerhost
- the host address of the remote peer- Returns:
- a future notified once the write completes.
-
close
Future<Void> close()
Closes theDatagramSocket
implementation asynchronous and notifies the handler once done.- Returns:
- a future notified once the socket is closed
-
localAddress
SocketAddress localAddress()
Return theSocketAddress
to which thisDatagramSocket
is bound.- Returns:
- the socket address
-
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 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 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 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 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 theHandler
once the operation completes.- 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 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 theHandler
once the operation completes.- 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 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 onhost
- the host to listen on- Returns:
- a future notified once the operation completes
-
handler
DatagramSocket handler(Handler<DatagramPacket> handler)
-
exceptionHandler
DatagramSocket exceptionHandler(Handler<Throwable> handler)
-
-