Visual C++ Examples

ChilkatHOMEAndroid™ASPVisual BasicVB.NETC#iOS (IPhone)Objective-CC++CMFCDelphiFoxProJavaPerl
PHP ExtensionPHP ActiveXPythonPowerShellRubySQL ServerVBScript

C++ Examples

CkString
Byte Array
Bounced Mail
Bz2
Character Encoding
CSV
DH Key Exchange
DKIM/DomainKeys
Digital Certificates
Digital Signatures
DSA
Email
Email Object
Encryption
FTP
HTML Conversion
HTTP
IMAP
MHT / HTML Email
POP3
RSA
S/MIME
SMTP
Socket
Spider
SSH Key
SSH
SSH Tunnel
SFTP
Tar
Upload
XML
XMP
Zip Compression


More Examples...
Amazon S3
NTLM
FileAccess
RSS
Atom
Self-Extractor
Service
PPMD
Deflate
Bzip2
LZW

 

 

 

 

 

 

 

 

Asynchronous DNS - Resolve 10 Hostnames Simultaneously

Downloads:

MS Windows Visual C/C++ Libraries
Linux/CentOS C/C++ Libraries
MAC OS X C/C++ Libraries
Solaris C/C++ Libraries
C++ Builder Libraries

C++ example code showing how to send 10 simultaneous DNS requests and then collect the results.

// Test asynchronous DNS by resolving 10 DNS hostnames simultaneously.
void TestAsyncDns(void)
    {
    // Create 10 socket objects.
    CkSocket *sock = new CkSocket[10];

    // Unlock once.
    sock[0].UnlockComponent("Anything for 30-day trial");

    // Resolve these 10 hostnames:
    const char *hostname[10] = {
	"www.chilkatsoft.com",
	"www.google.com",
	"www.microsoft.com",
	"www.apple.com",
	"www.ibm.com",
	"www.ebay.com",
	"www.amazon.com",
	"www.cknotes.com",
	"www.nytimes.com",
	"www.sony.com" };

    // Wait a maximum of 10 seconds.
    int maxWaitMs = 10000;

    int i;
    for (i=0; i<10; i++)
	{
	sock[i].AsyncDnsStart(hostname[i],maxWaitMs);
	}

    // Wait for all 10 to complete.
    while (true)
	{
	int numComplete = 0;
	for (i=0; i<10; i++)
	    {
	    if (sock[i].get_AsyncDnsFinished()) numComplete++;
	    }
	if (numComplete == 10) break;

	// Sleep 1/10th of a second.
	Sleep(100);
	}

    // Show the results:
    CkString strIpAddress;
    for (i=0; i<10; i++)
	{
	if (sock[i].get_AsyncDnsSuccess())
	    {
	    sock[i].get_AsyncDnsResult(strIpAddress);
	    printf("%s: %s\n",hostname[i],strIpAddress.getString());
	    }
	else
	    {
	    printf("%s: FAILED\n",hostname[i]);
	    }
	}

    delete [] sock;

    return;
    }

 

 

 

© 2000-2010 Chilkat Software, Inc. All Rights Reserved.

Mail Component · .NET Mail Component · XML Parser