Chilkat HOME ASP Visual Basic VB.NET C# Visual C++ C MFC Delphi FoxPro Java Perl PHP Python Ruby SQL Server VBScript
|
Asynchronous DNS - Resolve 10 Hostnames Simultaneously
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.tagtooga.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;
}
|
Need a specific example? Send a request to support@chilkatsoft.com
© 2000-2008 Chilkat Software, Inc. All Rights Reserved.