Schnittstelle DatagramIO<C extends DatagramIOConfiguration>
- Typparameter:
C- The type of the service's configuration.
- Alle Superschnittstellen:
Runnable
- Alle bekannten Implementierungsklassen:
DatagramIOImpl
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.
- Autor:
- Christian Bauer, Kai Kreuzer - added multicast response port
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungvoidinit(InetAddress bindAddress, int bindPort, Router router, DatagramProcessor datagramProcessor) Configures the service and starts any listening sockets.voidsend(DatagramPacket datagram) The actual sending of a UDP datagram.voidsend(OutgoingDatagramMessage message) Sends a datagram after conversion withDatagramProcessor.write(org.jupnp.model.message.OutgoingDatagramMessage).voidstop()Stops the service, closes any listening sockets.
-
Methodendetails
-
init
void init(InetAddress bindAddress, int bindPort, Router router, DatagramProcessor datagramProcessor) throws InitializationException Configures the service and starts any listening sockets.- Parameter:
bindAddress- The port to bind any sockets on. 0 means choosing an ephemeral portrouter- The router which handles receivedIncomingDatagramMessages.datagramProcessor- Reads and writes datagrams.- Löst aus:
InitializationException- If the service could not be initialized or started.
-
stop
void stop()Stops the service, closes any listening sockets. -
getConfiguration
C getConfiguration()- Gibt zurück:
- This service's configuration.
-
send
Sends a datagram after conversion withDatagramProcessor.write(org.jupnp.model.message.OutgoingDatagramMessage).- Parameter:
message- The message to send.
-
send
The actual sending of a UDP datagram.Recoverable errors should be logged, if appropriate only with debug level. Any non-recoverable errors should be thrown as
RuntimeExceptions.- Parameter:
datagram- The UDP datagram to send.
-