Implementing a Storage SCP
A Storage SCP receives DICOM objects from peer applications across the network. You can listen to incoming objects either synchronously or asynchronously.
For synchronous listening, the code can be as simple as:
DicomReader reader = new DicomReader(); StorageSCP scp = new StorageSCP(); reader.setInput(scp); BufferedImage image = reader.read(0);
new StorageSCP()
creates a new Storage SCP listening to the default DICOM port (104, administration right may be necessary) without encryption. It is used as the input of the reader instead of a usual input stream. Calling read
(or any method getting information about the object read, like getDicomMetadata()
), is blocking until an object is received.
Asynchronous listening is similar but doesn't block the calling thread. It requires the definition of a callback function that will be called each time an object is received:
final DicomReader reader = new DicomReader(); class Listener implements StorageSCPListener { public void objectReceived(ReceivedObject o) { reader.setInput(o); BufferedImage image = reader.read(0); /* ... */ } } new StorageSCP(new Listener()).start();
This time the input of the reader is set to the ReceivedObject
instance passed to the callback when an object is received.
Using a lambda expression, the code is still more concise:
final DicomReader reader = new DicomReader(); new StorageSCP(o -> { reader.setInput(o); BufferedImage image = reader.read(0); /* ... */ }).start();