... | ... | @@ -132,4 +132,39 @@ outputThread.join(); |
|
|
|
|
|
Starting the application with the option *OUTPUTSTREAM* creates an output stream socket so that all the stream can be retrieved.
|
|
|
|
|
|
Same example in Java:
|
|
|
```java
|
|
|
// Start the app with the OUTPUTSTREAM option.
|
|
|
Instance app = server.start("App2", Option.OUTPUTSTREAM);
|
|
|
|
|
|
// Get the outputstream socket.
|
|
|
OutputStreamSocket socket = app.getOutputStreamSocket();
|
|
|
|
|
|
// Define a thread to retrieve the output.
|
|
|
Thread outputThread = new Thread(() -> {
|
|
|
while (true) {
|
|
|
Output output = socket.receive();
|
|
|
if (output != null) {
|
|
|
System.out.println(output.getMessage());
|
|
|
}
|
|
|
else {
|
|
|
return;
|
|
|
}
|
|
|
}
|
|
|
});
|
|
|
outputThread.start();
|
|
|
|
|
|
// Wait for 1s.
|
|
|
try {
|
|
|
Thread.sleep(1000);
|
|
|
|
|
|
// Stop the output stream socket.
|
|
|
socket.cancel();
|
|
|
|
|
|
// Wait for the end of the thread.
|
|
|
outputThread.join();
|
|
|
|
|
|
}
|
|
|
catch (InterruptedException e) {
|
|
|
}
|
|
|
``` |