LEADTOOLS DICOM C++ Class Library Help > Classes and Member Functions > LDicomNet > LDicomNet Class Members > LDicomNet::Listen |
#include "ltdic.h"
L_INT LDicomNet::Listen(pszHostAddress, nHostPort, nNbPeers)
L_INT LDicomNet::Listen(pszHostAddress, nHostPort, nNbPeers, nIpType)
L_TCHAR * pszHostAddress; |
/* host IP address */ |
L_UINT nHostPort; |
/* host port number */ |
L_INT nNbPeers; |
/* backlog parameter */ |
L_INT nIpType; |
/* type of IP address */ |
Establishes a connection to listen for incoming connection requests. This function is available in the PACS Imaging Toolkit.
Parameter |
Description |
|
pszHostAddress |
Character string that contains the IP address of the host computer (the SCP's address). |
|
nHostPort |
Port number of the host (the SCP's port). |
|
nNbPeers |
Value passed to the WinSock listen() function for the backlog parameter that limits the size of the queue for waiting connections. |
|
nIpType |
The type of IP address. Possible values are: |
|
|
Value |
Meaning |
|
DICOM_IPTYPE_NONE |
[0x000] Provided for initialization. |
|
DICOM_IPTYPE_IPV4 |
[0x001] Only use IPv4 addresses. |
|
DICOM_IPTYPE_IPV6 |
[0x002] Only use IPv6 addresses. |
|
DICOM_IPTYPE_IPV4_OR_IPV6 |
[0x003] Use both IPv4 and IPv6 addresses. |
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 pszHostAddress is "*", the IP address will be all of the local computer's addresses. This is useful if the local computer has more than one network interface and 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 DICOM Network object using LDicomNet::LDicomNet . Then call LDicomNet::Connect to establish the connection.
To use your computer as an SCP, you must first create a DICOM Network object using LDicomNet::LDicomNet. Then call LDicomNet::Listen to listen for incoming connection requests.
The LDicomNet::Listen(pszHostAddress, nHostPort, nNbPeers, nIpType) overload allows you to specify which type of Internet Protocol Version to use. Pass DICOM_IPTYPE_IPV4 for nIpType to support the Internet Protocol version 4 (IPv4), which is the standard "dotted quad" 32-bit address format that has been in use since 1981. An example of an IPv4 address is 192.168.0.195
Pass DICOM_IPTYPE_IPV6 for nIpType to support Internet Protocol Version 6 (IPv6). IPv6 uses a 128-bit address format. An example of an IPv6 address is fe80::18bd:81f:6b02:759f
To support both IPv4 and Ipv6 addresses, pass DICOM_IPTYPE_IPV6 for nIpType.
If the call to LDicomNet::Listen() fails, make sure that the IP address that you passed for pszHostAddress is a valid address that is accessible within your network. Verify the accessibility of both IPv4 and IPv6 addresses using the windows ping command. For example, to verify that 192.168.0.195 is accessible within your network, perform the following steps:
Launch a command prompt, and type the following command
ping 192.168.0.195
The nNbPeers parameter designates the size of the backlog parameter used by the WinSock listen() function. As an example, suppose that the value is set to 3 and that 4 people try to connect at exactly the same time. In such a case, all 4 will be rejected because the connection backlog queue is full. But if one of the connections has been accepted by the time the 4th is made, then all will work.
To determine the number of connected clients and impose a maximum number of connections, perform the following steps:
Use the LDicomNet::GetClientCount function in the "OnReceiveAssociateRequest" handler.
Compare that value with the maximum number of connections allowed.
If the number of connected clients is greater than the maximum number of connections allowed, send a "SendAssociateReject" command to the client trying to connect.
Note that the following are equivalent:
pDicomNet->Listen(pszHostAddr4ess, nHostPort, nNbPeers);
pDicomNet->Listen(pszHostAddr4ess, nHostPort, nNbPeers, DICOM_IPTYPE_IPV4);
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 |
Win32, x64
See Also
Functions: |
|
Topics: |
Example
#define MAKE_IMAGE_PATH(pFileName) TEXT("C:\\Users\\Public\\Documents\\LEADTOOLS Images\\")pFileName L_INT LDicomNet_ListenExample(LMyDicomNet *m_pDicomNet) { L_INT nRet; //LMyDicomNet is a class derived from LDicomNet //m_pDicomNet is a member variable declared as: //set the temporary file path m_pDicomNet = new LMyDicomNet(MAKE_IMAGE_PATH(TEXT("temp")), DICOM_SECURE_NONE); L_TCHAR *strHostIP = TEXT(""); L_INT iPeerPort = 104; //startup the network nRet = m_pDicomNet->StartUp(); //create a server to accept up to 25 clients nRet = m_pDicomNet->Listen(strHostIP, iPeerPort, 25); if(nRet != DICOM_SUCCESS) return nRet; return DICOM_SUCCESS; }