def start_scp(path='./received/')
      if @accepted_abstract_syntaxes.size > 0 and @accepted_transfer_syntaxes.size > 0
        logger.info("Started DICOM SCP server on port #{@port}.")
        logger.info("Waiting for incoming transmissions...\n\n")
        # Initiate server:
        @scp = TCPServer.new(@host, @port)
        # Use a loop to listen for incoming messages:
        loop do
          Thread.start(@scp.accept) do |session|
            # Initialize the network package handler for this session:
            link = Link.new(:host_ae => @host_ae, :max_package_size => @max_package_size, :timeout => @timeout, :file_handler => @file_handler)
            link.set_session(session)
            # Note who has contacted us:
            logger.info("Connection established with:  #{session.peeraddr[2]}  (IP: #{session.peeraddr[3]})")
            # Receive an incoming message:
            segments = link.receive_multiple_transmissions
            info = segments.first
            # Interpret the received message:
            if info[:valid]
              association_error = check_association_request(info)
              unless association_error
                info, approved, rejected = process_syntax_requests(info)
                link.handle_association_accept(info)
                context = (LIBRARY.uid(info[:pc].first[:abstract_syntax]) ? LIBRARY.uid(info[:pc].first[:abstract_syntax]).name : 'Unknown UID!')
                if approved > 0
                  if approved == 1
                    logger.info("Accepted the association request with context: #{context}")
                  else
                    if rejected == 0
                      logger.info("Accepted all #{approved} proposed contexts in the association request.")
                    else
                      logger.warn("Accepted only #{approved} of #{approved+rejected} of the proposed contexts in the association request.")
                    end
                  end
                  # Process the incoming data. This method will also take care of releasing the association:
                  success, messages = link.handle_incoming_data(path)
                  # Pass along any messages that has been recorded:
                  messages.each { |m| logger.public_send(m.first, m.last) } if messages.first
                else
                  # No abstract syntaxes in the incoming request were accepted:
                  if rejected == 1
                    logger.warn("Rejected the association request with proposed context: #{context}")
                  else
                    logger.warn("Rejected all #{rejected} proposed contexts in the association request.")
                  end
                  # Since the requested abstract syntax was not accepted, the association must be released.
                  link.await_release
                end
              else
                # The incoming association was not formally correct.
                link.handle_rejection
              end
            else
              # The incoming message was not recognised as a valid DICOM message. Abort:
              link.handle_abort
            end
            # Terminate the connection:
            link.stop_session
            logger.info("Connection closed.\n\n")
          end
        end
      else
        raise "Unable to start SCP server as no accepted abstract syntaxes have been set!" if @accepted_abstract_syntaxes.length == 0
        raise "Unable to start SCP server as no accepted transfer syntaxes have been set!" if @accepted_transfer_syntaxes.length == 0
      end
    end
def start_scp(path='./received/')
      if @accepted_abstract_syntaxes.size > 0 and @accepted_transfer_syntaxes.size > 0
        logger.info("Started DICOM SCP server on port #{@port}.")
        logger.info("Waiting for incoming transmissions...\n\n")
        # Initiate server:
        @scp = TCPServer.new(@host, @port)
        # Use a loop to listen for incoming messages:
        loop do
          Thread.start(@scp.accept) do |session|
            # Initialize the network package handler for this session:
            link = Link.new(:host_ae => @host_ae, :max_package_size => @max_package_size, :timeout => @timeout, :file_handler => @file_handler)
            link.set_session(session)
            # Note who has contacted us:
            logger.info("Connection established with:  #{session.peeraddr[2]}  (IP: #{session.peeraddr[3]})")
            # Receive an incoming message:
            segments = link.receive_multiple_transmissions
            info = segments.first
            # Interpret the received message:
            if info[:valid]
              association_error = check_association_request(info)
              unless association_error
                info, approved, rejected = process_syntax_requests(info)
                link.handle_association_accept(info)
                context = (LIBRARY.uid(info[:pc].first[:abstract_syntax]) ? LIBRARY.uid(info[:pc].first[:abstract_syntax]).name : 'Unknown UID!')
                if approved > 0
                  if approved == 1
                    logger.info("Accepted the association request with context: #{context}")
                  else
                    if rejected == 0
                      logger.info("Accepted all #{approved} proposed contexts in the association request.")
                    else
                      logger.warn("Accepted only #{approved} of #{approved+rejected} of the proposed contexts in the association request.")
                    end
                  end
                  # Process the incoming data. This method will also take care of releasing the association:
                  success, messages = link.handle_incoming_data(path)
                  # Pass along any messages that has been recorded:
                  messages.each { |m| logger.public_send(m.first, m.last) } if messages.first
                else
                  # No abstract syntaxes in the incoming request were accepted:
                  if rejected == 1
                    logger.warn("Rejected the association request with proposed context: #{context}")
                  else
                    logger.warn("Rejected all #{rejected} proposed contexts in the association request.")
                  end
                  # Since the requested abstract syntax was not accepted, the association must be released.
                  link.await_release
                end
              else
                # The incoming association was not formally correct.
                link.handle_rejection
              end
            else
              # The incoming message was not recognised as a valid DICOM message. Abort:
              link.handle_abort
            end
            # Terminate the connection:
            link.stop_session
            logger.info("Connection closed.\n\n")
          end
        end
      else
        raise "Unable to start SCP server as no accepted abstract syntaxes have been set!" if @accepted_abstract_syntaxes.length == 0
        raise "Unable to start SCP server as no accepted transfer syntaxes have been set!" if @accepted_transfer_syntaxes.length == 0
      end
    end
Starts the Service Class Provider (SCP).

 This service acts as a simple storage node, which receives DICOM files
 and stores them in the specified folder.

 Customized storage actions can be set my modifying or replacing the FileHandler class.

 @param [String] path the directory where incoming files are to be saved