vertx.datagram documentation
Provides a broad set of functions for UDP servers and clients.
Usually you use a Datragram Client 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.
block-multicast-sender
(block-multicast-sender socket group-address source-address)(block-multicast-sender socket group-address source-address handler)(block-multicast-sender socket group-address source-address interface handler)
Blocks packets from the given source-address for the given group.
interface can be used to limit the block to a specific interface.
handler can either be a two-arity fn that will be passed the
exception-map (if any) and socket from the result of the block
call, or a Handler instance that will be called with the
AsyncResult object that wraps the exception and socket. Returns the
socket instance.
close
(close socket)(close socket handler)
Closes the socket.
handler can either be a single-arity fn that will be passed the
exception-map (if any) from the result of the close call, or a
Handler instance that will be called with the AsyncResult object
that wraps the exception.
join-multicast-group
(join-multicast-group socket group-address)(join-multicast-group socket group-address handler)(join-multicast-group socket group-address interface handler)(join-multicast-group socket group-address interface source-address handler)
Joins the socket to a multicast group.
interface and source-address can be used to limit the packets
received to a particular interface and source address,
respectively.
handler can either be a two-arity fn that will be passed the
exception-map (if any) and socket from the result of the join
call, or a Handler instance that will be called with the
AsyncResult object that wraps the exception and socket. Returns the
socket instance.
leave-multicast-group
(leave-multicast-group socket group-address)(leave-multicast-group socket group-address handler)(leave-multicast-group socket group-address interface handler)(leave-multicast-group socket group-address interface source handler)
Removes the socket from a multicast group.
interface and source-address must be used if they were used as part
of the join.
handler can either be a two-arity fn that will be passed the
exception-map (if any) and socket from the result of the leave
call, or a Handler instance that will be called with the
AsyncResult object that wraps the exception and socket. Returns the
socket instance.
listen
(listen socket port)(listen socket port host)(listen socket port host handler)
Makes socket listen to the given port and (optional) host.
handler can either be a two-arity fn that will be passed the
exception-map (if any) and socket from the result of the listen
call, or a Handler instance that will be called with the
AsyncResult object that wraps the exception and socket. Returns the
socket instance.
local-address
(local-address socket)
Returns the local address for the socket as an address-map.
This will be nil if listen hasn't been called for the socket.
on-data
(on-data socket handler)
Set a data handler on a socket.
As packets are read, the handler will be called with each packet of
the form:
{:sender address-map
:data data-as-a-buffer
:basis the-DatagramPacket-object}
handler can either be a Handler or a single-arity fn.
Returns the socket.send
(send socket content host port)(send socket content host port handler)
Writes the given bufferable content to the given host & port.
handler can either be a two-arity fn that will be passed the
exception-map (if any) and socket from the result of the send
call, or a Handler instance that will be called with the
AsyncResult object that wraps the exception and socket. Returns the
socket instance.
socket
(socket)(socket protocol-family)(socket protocol-family properties)
Creates a datagram socket (DatagramSocket) instance using vertx.core/*vertx*.
protocol-family can be one of :ipv4, ipv6. properties is a map of
properties to set on the newly created socket instance. They are
translated into .setXXX calls by camel-casing the keyword
key. Example: {:send-buffer-size 1024} will trigger a call
to .setSendBufferSize on the socket object. See the docuementation
for org.vertx.java.core.datagram.DatagramSocket for a full list of
properties.