L_DicomConnect

#include "ltdic.h"

L_LTDIC_API L_INT L_DicomConnect(hNet, pszHostAddress, nHostPort, pszPeerAddress, nPeerPort)

Connects an SCU to an SCP. This function is available in the Medical Imaging SuiteMedical Imaging Suite Toolkit.

Parameters

HDICOMNET hNet

A DICOM Network handle. This is the handle returned from the L_DicomCreateNet function.

L_TCHAR * pszHostAddress

Character string that contains the IP address of the host computer (the client's address).

L_UINT nHostPort

Port number of the host (the client's port).

L_TCHAR * pszPeerAddress

Character string that contains the IP address of the peer computer to which to connect (the server's address).

L_UINT nPeerPort

Port number of the peer computer to which to connect (the server's port).

Returns

Value Meaning
DICOM_SUCCESS The function was successful.
>0 An error occurred. Refer to Return Codes.

Comments

If pszHostAddress is " or NULL, the IP address will be the local computer's address.

If nHostPort is 0, the port number will be the number of the first available port.  In most cases, you should pass 0 for this parameter.  If you pass any port number other than 0, that port number will be used for the first connection and when you close the connection, LEADTOOLS will wait for the internal TCP timeout before releasing the port. This may lead to problems reconnecting.  If you pass 0, then on subsequent connections LEADTOOLS will use the next available port.

To connect to a server as a client, you must first create and initialize a handle to the DICOM Network using L_DicomCreateNet. Next, set the callback functions you will use by calling L_DicomSetCallback. Then call L_DicomConnect or L_DicomConnectExt  to establish the connection.

To use your computer as a server, you must first create and initialize a handle to the DICOM Network using L_DicomCreateNet. Next, set the callback functions you will use by calling L_DicomSetCallback. Then call L_DicomListen or L_DicomListenExt to listen for incoming connection requests.

When a client calls this function, it generates an ACCEPTCALLBACK function call on the server, provided the server has set the ACCEPTCALLBACK using L_DicomSetCallback.

L_DicomConnectExt and L_DicomListenExt support both iPv4 and iPv6.

Required DLLs and Libraries

Platforms

Win32, x64, Linux.

See Also

Functions

Topics

Example

L_VOID EXT_CALLBACK OnAccept(HDICOMNET hNet, L_INT nError, L_VOID* pUserData); 
L_VOID EXT_CALLBACK OnReceive(HDICOMNET hNet, L_INT nError, L_UCHAR nType, L_UCHAR* pBuffer, L_UINT32 nBytes, L_VOID* pUserData); 
L_VOID EXT_CALLBACK OnSend(HDICOMNET hNet, L_INT nError, L_UCHAR nType, L_UINT32 nBytes, L_VOID* pUserData); 
L_VOID EXT_CALLBACK OnReceiveAssociateRequest(HDICOMNET hNet, HDICOMPDU hAssociate, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveReleaseRequest(HDICOMNET hNet, L_VOID* pUserData); 
L_VOID EXT_CALLBACK OnReceiveAbort(HDICOMNET hNet, L_UCHAR nSource, L_UCHAR nReason, L_VOID* pUserData); 
L_VOID EXT_CALLBACK OnReceiveData(HDICOMNET hNet, L_UCHAR nID, HDICOMDS hCS, HDICOMDS hDS, L_VOID* pUserData); 
L_VOID EXT_CALLBACK OnReceiveCStoreRequest(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_TCHAR *pszInstance, L_UINT16 nPriority, L_TCHAR *pszMoveAE, L_UINT16 nMoveMessageID, HDICOMDS hDS, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveCStoreResponse(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_TCHAR *pszInstance, L_UINT16 nStatus, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveCFindRequest(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_UINT16 nPriority, HDICOMDS hDS, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveCFindResponse(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_UINT16 nStatus, HDICOMDS hDS, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveCGetRequest(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_UINT16 nPriority, HDICOMDS hDS, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveCGetResponse(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_UINT16 nStatus, L_UINT16 nRemaining, L_UINT16 nCompleted, L_UINT16 nFailed, L_UINT16 nWarning, HDICOMDS hDS, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveCMoveRequest(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR* pszClass, L_UINT16 nPriority, L_TCHAR* pszMoveAE, HDICOMDS hDS, L_VOID* pUserData); 
L_VOID EXT_CALLBACK OnReceiveCMoveResponse(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_UINT16 nStatus, L_UINT16 nRemaining, L_UINT16 nCompleted, L_UINT16 nFailed, L_UINT16 nWarning, HDICOMDS hDS, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveCCancelRequest(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveCEchoRequest(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR* pszClass, L_VOID* pUserData); 
L_VOID EXT_CALLBACK OnReceiveCEchoResponse(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_UINT16 nStatus, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveNReportRequest(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_TCHAR *pszInstance, L_UINT16 nEvent, HDICOMDS hDS, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveNReportResponse(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_TCHAR *pszInstance, L_UINT16 nStatus, L_UINT16 nEvent, HDICOMDS hDS, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveNGetRequest(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_TCHAR *pszInstance, L_UINT32 *pnAttribute, L_UINT32 nCount, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveNGetResponse(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_TCHAR *pszInstance, L_UINT16 nStatus, HDICOMDS hDS, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveNSetRequest(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_TCHAR *pszInstance, HDICOMDS hDS, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveNSetResponse(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_TCHAR *pszInstance, L_UINT16 nStatus, HDICOMDS hDS, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveNActionRequest(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_TCHAR *pszInstance, L_UINT16 nAction, HDICOMDS hDS, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveNActionResponse  (HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_TCHAR *pszInstance, L_UINT16 nStatus, L_UINT16 nAction, HDICOMDS hDS, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveNCreateRequest(HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_TCHAR *pszInstance, HDICOMDS hDS, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveNCreateResponse  (HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_TCHAR *pszInstance, L_UINT16 nStatus, HDICOMDS hDS, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveNDeleteRequest   (HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_TCHAR *pszInstance, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveNDeleteResponse  (HDICOMNET hNet, L_UCHAR nPresentationID, L_UINT16 nMessageID, L_TCHAR *pszClass, L_TCHAR *pszInstance, L_UINT16 nStatus, L_VOID *pUserData); 
L_VOID EXT_CALLBACK OnReceiveUnknown(HDICOMNET hNet, L_UCHAR nPresentationID, HDICOMDS hCS, HDICOMDS hDS, L_VOID *pUserData); 
 
L_VOID EXT_CALLBACK OnConnect(HDICOMNET hNet, L_INT nError, L_VOID *pUserData) 
{ 
   UNREFERENCED_PARAMETER(pUserData); 
   UNREFERENCED_PARAMETER(hNet); 
    
   if (nError != DICOM_SUCCESS) 
      MessageBox(NULL, TEXT("Connection refused"), TEXT("Notice"), MB_OK); 
   else 
      MessageBox(NULL, TEXT("Connection Accepted"), TEXT("Notice"), MB_OK); 
} 
 
L_VOID EXT_CALLBACK OnClose(HDICOMNET hNet, L_INT nError, HDICOMNET hPeer, L_VOID *pUserData) 
{ 
   UNREFERENCED_PARAMETER(nError); 
   UNREFERENCED_PARAMETER(hPeer); 
   UNREFERENCED_PARAMETER(pUserData); 
    
   L_TCHAR szMsg[200]; 
   L_TCHAR szTemp[200]; 
   L_TCHAR szURL[200]; 
   L_UINT uPort; 
   L_INT nRet; 
 
   lstrcpy(szMsg, TEXT("*** NetClose Event ***\n")); 
 
   /* display some information about the connection: */ 
   lstrcat(szMsg, TEXT("Host [")); 
   nRet = L_DicomGetHostInfo(hNet, szURL, 200, &uPort); 
   if (nRet != DICOM_SUCCESS) 
      MessageBox(NULL, TEXT("Error in callback function"), TEXT("OnClose Callback"), MB_OK); 
 
   lstrcat(szMsg, szURL); 
   lstrcat(szMsg, TEXT("]\n")); 
   wsprintf(szTemp, TEXT("Port[%d]\n\n"), uPort); 
   lstrcat(szMsg, szTemp); 
   lstrcat(szMsg, TEXT("Peer[")); 
   nRet = L_DicomGetPeerInfo(hNet, szURL, 200, &uPort); 
   if (nRet != DICOM_SUCCESS) 
      MessageBox(NULL, TEXT("Error in callback function"), TEXT("OnClose Callback"), MB_OK); 
 
   lstrcat(szMsg, szURL); 
   lstrcat(szMsg, TEXT("]\n")); 
   wsprintf(szTemp, TEXT("Port[%d]\n"), uPort); 
   lstrcat(szMsg, szTemp); 
   MessageBox(NULL, szMsg, TEXT("Close"), MB_OK); 
} 
 
L_VOID EXT_CALLBACK OnReceiveReleaseResponse(HDICOMNET hNet, L_VOID *pUserData) 
{ 
   UNREFERENCED_PARAMETER(pUserData); 
   L_TCHAR szMsg[200]; 
   lstrcpy(szMsg, TEXT("*** NetReceiveReleaseResponse Event ***\n")); 
   MessageBox(NULL, szMsg, TEXT("OnReceiveReleaseResponse"), MB_OK); 
   L_DicomClose(hNet); 
} 
 
L_VOID EXT_CALLBACK OnReceiveAssociateAccept(HDICOMNET hNet, HDICOMPDU hAssociate, L_VOID *pUserData) 
{ 
   UNREFERENCED_PARAMETER(pUserData); 
   UNREFERENCED_PARAMETER(hAssociate); 
   UNREFERENCED_PARAMETER(hNet); 
   L_TCHAR szMsg[800]; 
   wsprintf(szMsg, TEXT("*** OnReceiveAssociateAccept ***\nIsAssociated[%d]"),L_DicomIsAssociated(hNet)); 
   MessageBox(NULL, szMsg, TEXT("OnReceiveAssociateAccept"), MB_OK); 
} 
 
L_VOID EXT_CALLBACK OnReceiveAssociateReject(HDICOMNET hNet, L_UCHAR nResult, L_UCHAR nSource, L_UCHAR nReason, L_VOID *pUserData) 
{ 
   UNREFERENCED_PARAMETER(hNet); 
   UNREFERENCED_PARAMETER(pUserData); 
   L_TCHAR szMsg[800]; 
   wsprintf(szMsg, TEXT("*** OnReceiveAssociateReject ***\nResult[%d]\nSource[%d]\nReason[%d]"), nResult, nSource, nReason); 
   MessageBox(NULL, szMsg, TEXT("OnReceiveAssociateReject"), MB_OK); 
} 
 
L_INT DicomConnectExample(L_VOID) 
{ 
   L_INT nRet; 
   L_UINT iHostPort = 0; 
   L_UINT iPeerPort = 104; 
   L_TCHAR szHostIP[200]; 
   L_TCHAR szPeerIP[200]; 
   DICOMNETCALLBACK cb; 
   HDICOMNET hNet; 
 
   /* start the network */ 
   nRet = L_DicomStartUp(); 
   if (nRet != DICOM_SUCCESS) 
      return nRet; 
 
   /* set the temporary file path */ 
   hNet = L_DicomCreateNet(MAKE_IMAGE_PATH(TEXT("")), DICOM_SECURE_NONE); 
 
   lstrcpy(szHostIP, TEXT("")); /* empty string means use local IP */ 
   lstrcpy(szPeerIP, TEXT("207.238.49.195")); /* valid IP address of computer to connect to */ 
 
   /* set the callbacks */ 
   memset(&cb, 0, sizeof(DICOMNETCALLBACK)); 
   cb.pfnConnect = (CONNECTCALLBACK)OnConnect; 
   cb.pfnAccept = (ACCEPTCALLBACK)OnAccept; 
   cb.pfnClose = (CLOSECALLBACK)OnClose; 
   cb.pfnReceive = (RECEIVECALLBACK)OnReceive; 
   cb.pfnSend = (SENDCALLBACK) OnSend; 
   cb.pfnReceiveAssociateRequest = (RECEIVEASSOCIATEREQUESTCALLBACK)OnReceiveAssociateRequest; 
   cb.pfnReceiveReleaseRequest = (RECEIVERELEASEREQUESTCALLBACK)OnReceiveReleaseRequest; 
   cb.pfnReceiveReleaseResponse  = (RECEIVERELEASERESPONSECALLBACK)OnReceiveReleaseResponse; 
   cb.pfnReceiveAbort = (RECEIVEABORTCALLBACK)OnReceiveAbort; 
   cb.pfnReceiveData = (RECEIVEDATACALLBACK)OnReceiveData; 
   cb.pfnReceiveAssociateAccept = (RECEIVEASSOCIATEACCEPTCALLBACK)OnReceiveAssociateAccept; 
   cb.pfnReceiveAssociateReject = (RECEIVEASSOCIATEREJECTCALLBACK)OnReceiveAssociateReject; 
   cb.pfnReceiveCStoreRequest = (RECEIVECSTOREREQUESTCALLBACK)OnReceiveCStoreRequest; 
   cb.pfnReceiveCStoreResponse = (RECEIVECSTORERESPONSECALLBACK)OnReceiveCStoreResponse; 
   cb.pfnReceiveCFindRequest = (RECEIVECFINDREQUESTCALLBACK)OnReceiveCFindRequest; 
   cb.pfnReceiveCFindResponse = (RECEIVECFINDRESPONSECALLBACK)OnReceiveCFindResponse; 
   cb.pfnReceiveCGetRequest = (RECEIVECGETREQUESTCALLBACK)OnReceiveCGetRequest; 
   cb.pfnReceiveCGetResponse = (RECEIVECGETRESPONSECALLBACK)OnReceiveCGetResponse; 
   cb.pfnReceiveCMoveRequest = (RECEIVECMOVEREQUESTCALLBACK)OnReceiveCMoveRequest; 
   cb.pfnReceiveCMoveResponse = (RECEIVECMOVERESPONSECALLBACK)OnReceiveCMoveResponse; 
   cb.pfnReceiveCCancelRequest = (RECEIVECCANCELREQUESTCALLBACK)OnReceiveCCancelRequest; 
   cb.pfnReceiveCEchoRequest = (RECEIVECECHOREQUESTCALLBACK)OnReceiveCEchoRequest; 
   cb.pfnReceiveCEchoResponse = (RECEIVECECHORESPONSECALLBACK)OnReceiveCEchoResponse; 
   cb.pfnReceiveNReportRequest = (RECEIVENREPORTREQUESTCALLBACK)OnReceiveNReportRequest; 
   cb.pfnReceiveNReportResponse = (RECEIVENREPORTRESPONSECALLBACK)OnReceiveNReportResponse; 
   cb.pfnReceiveNGetRequest = (RECEIVENGETREQUESTCALLBACK)OnReceiveNGetRequest; 
   cb.pfnReceiveNGetResponse = (RECEIVENGETRESPONSECALLBACK)OnReceiveNGetResponse; 
   cb.pfnReceiveNSetRequest = (RECEIVENSETREQUESTCALLBACK)OnReceiveNSetRequest; 
   cb.pfnReceiveNSetResponse = (RECEIVENSETRESPONSECALLBACK)OnReceiveNSetResponse; 
   cb.pfnReceiveNActionRequest = (RECEIVENACTIONREQUESTCALLBACK)OnReceiveNActionRequest; 
   cb.pfnReceiveNActionResponse = (RECEIVENACTIONRESPONSECALLBACK)OnReceiveNActionResponse; 
   cb.pfnReceiveNCreateRequest = (RECEIVENCREATEREQUESTCALLBACK)OnReceiveNCreateRequest; 
   cb.pfnReceiveNCreateResponse = (RECEIVENCREATERESPONSECALLBACK)OnReceiveNCreateResponse; 
   cb.pfnReceiveNDeleteRequest = (RECEIVENDELETEREQUESTCALLBACK)OnReceiveNDeleteRequest; 
   cb.pfnReceiveNDeleteResponse = (RECEIVENDELETERESPONSECALLBACK)OnReceiveNDeleteResponse; 
   cb.pfnReceiveUnknown = (RECEIVEUNKNOWNCALLBACK)OnReceiveUnknown; 
   cb.pUserData = NULL; 
   L_DicomSetCallback(hNet, &cb); 
 
   /* connect to a server */ 
   return L_DicomConnect(hNet, szHostIP, iHostPort, szPeerIP, iPeerPort); 
} 
Help Version 20.0.2020.4.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2020 LEAD Technologies, Inc. All Rights Reserved.

LEADTOOLS DICOM C API Help