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.fourthline.cling.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,
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.fourthline.cling.model.message.OutgoingDatagramMessage) . |
void |
stop()
Stops the service, closes any listening sockets.
|
void init(InetAddress bindAddress, Router router, DatagramProcessor datagramProcessor) throws InitializationException
bindAddress
- The address to bind any sockets on.router
- The router which handles received IncomingDatagramMessage
s.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.fourthline.cling.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 RuntimeException
s.
datagram
- The UDP datagram to send.Copyright © 2016 4th Line GmbH, Switzerland. All rights reserved.