L_DicomConnect

#include "ltdic.h"

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

HDICOMNET hNet;

/* a DICOM Network handle */

L_CHAR * pszHostAddress;

/* host IP address */

L_UINT nHostPort;

/* host port number */

L_CHAR * pszPeerAddress;

/* peer IP address */

L_UINT nPeerPort;

/* peer port number */

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

Parameter

Description

hNet

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

pszHostAddress

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

nHostPort

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

pszPeerAddress

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

nPeerPort

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

Returns

0

SUCCESS

>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.

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 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 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.

Required DLLs and Libraries

LTDIC

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application

See Also

Functions:

L_DicomCreateNet, L_DicomStartUp, L_DicomListen

Topics:

Working with DICOM Network Connections

Example

L_VOID Test(L_VOID)
{
   L_INT nRet;
   L_UINT iHostPort = 0;
   L_UINT iPeerPort = PEER_PORT;
   L_CHAR szHostIP[200];
   L_CHAR szPeerIP[200];
   DICOMNETCALLBACK cb;
   HDICOMNET hNet;

   /* start the network */
   nRet = L_DicomStartUp();

   /* set the temporary file path */
   hNet = L_DicomCreateNet("d:\\temp", DICOM_SECURE_NONE);

   lstrcpy(szHostIP, ""); /* empty string means use local IP */
   lstrcpy(szPeerIP, "207.238.49.195"); /* valid IP addres 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 */
   L_DicomConnect(hNet, szHostIP, iHostPort, szPeerIP, iPeerPort);
}

L_VOID L_EXPORT EXT_CALLBACK OnConnect(HDICOMNET hNet, L_INT nError, L_VOID *pUserData)
{
   if (nError != DICOM_SUCCESS)
   {
      MessageBox(NULL, "Connection refused", "Notice", MB_OK);
   }
   else
   {
      MessageBox(NULL, "Connection Accepted", "Notice", MB_OK);
   }
}

L_VOID L_EXPORT EXT_CALLBACK OnClose(HDICOMNET hNet, L_INT nError, HDICOMNET hPeer, L_VOID *pUserData)
{
   L_CHAR szMsg[200];
   L_CHAR szTemp[200];
   L_CHAR szURL[200];
   L_UINT uPort;

   lstrcpy(szMsg, "*** NetClose Event ***\n");

   /* display some information about the connection: */
   lstrcat(szMsg, "Host [");
   L_DicomGetHostInfo(hNet, szURL, &uPort);
   lstrcat(szMsg, szURL);
   lstrcat(szMsg, "]\n");
   wsprintf(szTemp, "Port[%d]\n\n", uPort);
   lstrcat(szMsg, szTemp);
   lstrcat(szMsg, "Peer[");
   L_DicomGetPeerInfo(hNet, szURL, &uPort);
   lstrcat(szMsg, szURL);
   lstrcat(szMsg, "]\n");
   wsprintf(szTemp, "Port[%d]\n", uPort);
   lstrcat(szMsg, szTemp);
   MessageBox(NULL, szMsg, "Close", MB_OK);
}

L_VOID L_EXPORT EXT_CALLBACK OnReceiveReleaseResponse(HDICOMNET hNet, L_VOID *pUserData)
{
   L_CHAR szMsg[200];
   lstrcpy(szMsg, "*** NetReceiveReleaseResponse Event ***\n");
   MessageBox(NULL, szMsg, "OnReceiveReleaseResponse", MB_OK);
   L_DicomClose(hNet);
}

L_VOID L_EXPORT EXT_CALLBACK OnReceiveAssociateAccept(HDICOMNET hNet, HDICOMPDU hAssociate, L_VOID *pUserData)
{
   L_CHAR szMsg[800];
   wsprintf(szMsg, "*** OnReceiveAssociateAccept ***\nIsAssociated[%d]",L_DicomIsAssociated(hNet));
   MessageBox(NULL, szMsg, "OnReceiveAssociateAccept", MB_OK);
}

L_VOID L_EXPORT EXT_CALLBACK OnReceiveAssociateReject(HDICOMNET hNet, L_UCHAR nResult, L_UCHAR nSource, L_UCHAR nReason, L_VOID *pUserData)
{
   L_CHAR szMsg[800];
   wsprintf(szMsg, "*** OnReceiveAssociateReject ***\nResult[%d]\nSource[%d]\nReason[%d]", nResult, nSource, nReason);
   MessageBox(NULL, szMsg, "OnReceiveAssociateReject", MB_OK);
}