Package org.jupnp.transport.spi
Schnittstelle StreamServer<C extends StreamServerConfiguration>
- Typparameter:
C- The type of the service's configuration.
- Alle Superschnittstellen:
Runnable
- Alle bekannten Implementierungsklassen:
ServletStreamServerImpl
Service for receiving TCP (HTTP) streams, one per bound IP address.
This service typically listens on a socket for TCP connections.
This listening loop is started with the run() method, this service is
Runnable. Then Router.received(UpnpStream) is called with a custom
UpnpStream. This will start processing of the request and run() the
UpnpStream (which is also Runnable) in a separate thread,
freeing up the receiving thread immediately.
The UpnpStream then creates a StreamRequestMessage
and calls the UpnpStream.process(org.jupnp.model.message.StreamRequestMessage)
method. The UpnpStream then returns the response to the network client.
In pseudo-code:
MyStreamServer implements StreamServer {
run() {
while (not stopped) {
Connection con = listenToSocketAndBlock();
router.received( new MyUpnpStream(con) );
}
}
}
MyUpnpStream(con) extends UpnpStream {
run() {
try {
StreamRequestMessage request = // ... Read request
StreamResponseMessage response = process(request);
// ... Send response
responseSent(response))
} catch (Exception e) {
responseException(e);
}
}
}
An implementation has to be thread-safe.
- Autor:
- Christian Bauer
-
Methodenübersicht
Modifizierer und TypMethodeBeschreibungintgetPort()This method will be called potentially right afterinit(java.net.InetAddress, org.jupnp.transport.Router), the actual assigned local port must be available before the server is started.voidinit(InetAddress bindAddress, Router router) Configures the service and starts any listening sockets.voidstop()Stops the service, closes any listening sockets.
-
Methodendetails
-
init
Configures the service and starts any listening sockets.- Parameter:
bindAddress- The address to bind any sockets on.router- The router which handles the incomingUpnpStream.- Löst aus:
InitializationException- If the service could not be initialized or started.
-
getPort
int getPort()This method will be called potentially right afterinit(java.net.InetAddress, org.jupnp.transport.Router), the actual assigned local port must be available before the server is started.- Gibt zurück:
- The TCP port this service is listening on, e.g. the actual ephemeral port.
-
stop
void stop()Stops the service, closes any listening sockets. -
getConfiguration
C getConfiguration()- Gibt zurück:
- This service's configuration.
-