ctkDICOMDemoSCUMain.cpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*=========================================================================
  2. Library: CTK
  3. Copyright (c) 2010 Kitware Inc.
  4. Licensed under the Apache License, Version 2.0 (the "License");
  5. you may not use this file except in compliance with the License.
  6. You may obtain a copy of the License at
  7. http://www.commontk.org/LICENSE
  8. Unless required by applicable law or agreed to in writing, software
  9. distributed under the License is distributed on an "AS IS" BASIS,
  10. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. See the License for the specific language governing permissions and
  12. limitations under the License.
  13. =========================================================================*/
  14. #include "dcmtk/config/osconfig.h" /* make sure OS specific configuration is included first */
  15. #include "dcmtk/dcmnet/scu.h"
  16. // STD includes
  17. #include <cstdlib>
  18. #include <iostream>
  19. #include <fstream>
  20. void print_usage()
  21. {
  22. std::cerr << "Usage: \n";
  23. std::cerr << " ctkDICOMDemoSCU peer port\n";
  24. std::cerr << " Issues ECHO request to the given host and given port.\n";
  25. return;
  26. }
  27. int main(int argc, char** argv)
  28. {
  29. // Check whether host and port are given
  30. if (argc < 3)
  31. {
  32. print_usage();
  33. return 2;
  34. }
  35. std::string host = argv[1];
  36. unsigned int port = atoi(argv[2]);
  37. // Setup SCU
  38. DcmSCU scu;
  39. scu.setPeerHostName(host);
  40. scu.setPeerPort(port);
  41. OFString verificationSOP = UID_VerificationSOPClass;
  42. OFList<OFString> ts;
  43. ts.push_back(UID_LittleEndianExplicitTransferSyntax);
  44. ts.push_back(UID_BigEndianExplicitTransferSyntax);
  45. ts.push_back(UID_LittleEndianImplicitTransferSyntax);
  46. scu.addPresentationContext(verificationSOP, ts);
  47. OFCondition result = scu.initNetwork();
  48. if (result.bad())
  49. {
  50. std::cerr << "Error setting up SCU: " << result.text() << "\n";
  51. return 2;
  52. }
  53. // Negotiate association
  54. result = scu.negotiateAssociation();
  55. if (result.bad())
  56. {
  57. std::cerr << "Error negotiating association: " << result.text() << "\n";
  58. return 2;
  59. }
  60. // Issue ECHO request and let scu find presentation context itself (0)
  61. result = scu.sendECHORequest(0);
  62. if (result.bad())
  63. {
  64. std::cerr << "Error issuing ECHO request or received rejecting response: " << result.text() << "\n";
  65. return 2;
  66. }
  67. std::cout << "Successfully sent DICOM Echo to host " << argv[1] << " on port " << argv[2] << "\n";
  68. return 0;
  69. }