C - The type of the service's configuration.public interface DatagramIO<C extends DatagramIOConfiguration> extends Runnable
This service typically listens on a socket for UDP unicast datagrams, with an ephemeral port.
This listening loop is started with the run() method,
this service is Runnable. Any received datagram is then converted into an
IncomingDatagramMessage and
handled by the
Router.received(org.jupnp.model.message.IncomingDatagramMessage)
method. This conversion is the job of the DatagramProcessor.
Clients of this service use it to send UDP datagrams, either to a unicast
or multicast destination. Any OutgoingDatagramMessage can
be converted and written into a datagram with the DatagramProcessor.
An implementation has to be thread-safe.
| Modifier and Type | Method and Description |
|---|---|
C |
getConfiguration() |
void |
init(InetAddress bindAddress,
int bindPort,
Router router,
DatagramProcessor datagramProcessor)
Configures the service and starts any listening sockets.
|
void |
send(DatagramPacket datagram)
The actual sending of a UDP datagram.
|
void |
send(OutgoingDatagramMessage message)
Sends a datagram after conversion with
DatagramProcessor.write(org.jupnp.model.message.OutgoingDatagramMessage). |
void |
stop()
Stops the service, closes any listening sockets.
|
void init(InetAddress bindAddress, int bindPort, Router router, DatagramProcessor datagramProcessor) throws InitializationException
bindAddress - The address to bind any sockets on.bindAddress - The port to bind any sockets on. 0 means choosing an ephemeral portrouter - The router which handles received IncomingDatagramMessages.datagramProcessor - Reads and writes datagrams.InitializationException - If the service could not be initialized or started.void stop()
C getConfiguration()
void send(OutgoingDatagramMessage message)
DatagramProcessor.write(org.jupnp.model.message.OutgoingDatagramMessage).message - The message to send.void send(DatagramPacket datagram)
Recoverable errors should be logged, if appropriate only with debug level. Any
non-recoverable errors should be thrown as RuntimeExceptions.
datagram - The UDP datagram to send.Copyright © 2023 jUPnP.org. All rights reserved.