Create an Object to Connect to a Node

The name of the Connect:Direct® node and the connection information is set at object creation time using the CDNode constructor. If a parameter is not supplied (NULL pointer), the default value for that parameter is read from the Registry. During construction, the CDNode object attempts to connect to the physical Connect:Direct node using the protocol information contained in the Registry. If the connection fails, the CDConnectionException is returned. If the connection is successful but the logon is denied by the server, a CDLogonException is returned.

The CDNode object creates and removes the connection to the Connect:Direct node as needed. Connections are shared and reused as different requests are made. The following section of the class definition displays the methods to construct a CDNode object and methods to retrieve node information:

 // Constructor for CDNode 
       int nProtocol=CD_PROTOCOL_TCPIP); 
CDNode(LPCTSTR szFilename); 
CDNode(const CDNode &Node); 
//Node Information Methods 
const CString GetName() const; 
LPCTSTR GetCDName() const; 
LPCTSTR GetUserid() const; 
LPCTSTR GetServer() const; 
int GetProtocol();

The following two examples illustrate two different methods for creating a CDNode object. The first method creates the CDNode object locally on the stack. The second example creates a dynamic allocation of a CDNode object from the stack. Both methods then execute a SELECT PROCESS command using the CDNode object.

     CDSelectProcCmd cmd; 
     //Execute the "SELECT PROCESS" command 
     CDProcIterator it = cmd.Execute(MyNode); 
     CDNode *pNode = new CDNode("MYNODE", "MYUSERID", "MYPASSWORD"); 
     CDSelectProcCmd cmd; 
     //Execute the "SELECT PROCESS" command 
     CDProcIterator it = cmd.Execute(pNode); 
     delete pNode;