SGyves
asked on
CSocket Question
I have a program that connects to a server using a CSocket. There are a list of servers that are available to the application. So what I want is this...if the application cannot connect to the first server...I want it to cycle through a list until it either runs out of servers to try, or makes a good connection. So at the connect statement, I have it check to see if it was successful...if not...I change the server and port parameters and try again. For some reason...this is not working. Is there something I have to do to the socket in order to make this process work? Right now it does not work. Do I have to reinitialize the socket before I try another server? How can I make this work correctly? Here is my code for the loop:
if(ircSock->Connect() == FALSE)
{
//Here is where we are going to cycle through all possible servers
POSITION aPos = dPtr->GetServerList()->Get HeadPositi on();
CIRCServer* nextServer;
bool success = false;
while(aPos && (success == false))
{
nextServer = dPtr->GetServerList()->Get Next(aPos) ;
ircSock->SetServer(nextSer ver->GetSe rver());
ircSock->SetPort(nextServe r->GetRand omPort());
if(ircSock->Connect() == TRUE)
{
success = true;
}
}
if(!(aPos))
{
SetEvent(dPtr->m_hContinue Close);
return 0;
}
}
if(ircSock->Connect() == FALSE)
{
//Here is where we are going to cycle through all possible servers
POSITION aPos = dPtr->GetServerList()->Get
CIRCServer* nextServer;
bool success = false;
while(aPos && (success == false))
{
nextServer = dPtr->GetServerList()->Get
ircSock->SetServer(nextSer
ircSock->SetPort(nextServe
if(ircSock->Connect() == TRUE)
{
success = true;
}
}
if(!(aPos))
{
SetEvent(dPtr->m_hContinue
return 0;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Ohh yes, after the Create(0, then call Connect().Create will call Bind.
Just a try out, not sure
Just a try out, not sure
ASKER
Sorry for the delay on the points Rosh.
ASKER