Interface DatagramSocket
- All Superinterfaces:
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 Summary
Modifier and TypeMethodDescriptionblockMulticastGroup(String multicastAddress, String sourceToBlock) Block the given address for the given multicast address and notifies theHandleronce the operation completes.blockMulticastGroup(String multicastAddress, String networkInterface, String sourceToBlock) Block the given address for the given multicast address on the given network interface and notifies theHandleronce the operation completes.close()Closes theDatagramSocketimplementation asynchronous and notifies the handler once done.exceptionHandler(Handler<Throwable> handler) handler(Handler<DatagramPacket> handler) Start listening on the given port and host.listenMulticastGroup(String multicastAddress) Joins a multicast group and listens for packets send to it.listenMulticastGroup(String multicastAddress, String networkInterface, String source) Joins a multicast group and listens for packets send to it on the given network interface.Return theSocketAddressto which thisDatagramSocketis bound.Write the givenBufferto theSocketAddress.Write the givenStringto theSocketAddressusing UTF8 encoding.Write the givenStringto theSocketAddressusing the given encoding.unlistenMulticastGroup(String multicastAddress) Leaves a multicast group and stops listening for packets send to it.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 Measured
isMetricsEnabled
-
Method Details
-
send
-
sender
- Parameters:
port- the port of the remote peerhost- the host address of the remote peer- Returns:
- the write stream for sending packets
-
send
-
send
Write the givenStringto theSocketAddressusing the given encoding.- 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 future notified once the write completes.
-
close
Closes theDatagramSocketimplementation asynchronous and notifies the handler once done.- Returns:
- a future notified once the socket is closed
-
localAddress
SocketAddress localAddress()Return theSocketAddressto which thisDatagramSocketis bound.- Returns:
- the socket address
-
listenMulticastGroup
-
listenMulticastGroup
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
-
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
Block the given address for the given multicast address and notifies theHandleronce 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 theHandleronce 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
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
-
exceptionHandler
-