Solved

CSocket Question

Posted on 2003-11-06
4
340 Views
Last Modified: 2013-11-20
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()->GetHeadPosition();
            CIRCServer* nextServer;
            bool success = false;

            while(aPos && (success == false))
            {
                  nextServer = dPtr->GetServerList()->GetNext(aPos);
                  ircSock->SetServer(nextServer->GetServer());
                  ircSock->SetPort(nextServer->GetRandomPort());
                  if(ircSock->Connect() == TRUE)
                  {
                        success = true;
                  }
            }
            if(!(aPos))
            {
                  SetEvent(dPtr->m_hContinueClose);      
                  return 0;
            }            
      }

0
Comment
Question by:SGyves
  • 2
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
Roshan Davis earned 400 total points
ID: 9698762
Try this, just a guess

         while(aPos && (success == false))
         {
              nextServer = dPtr->GetServerList()->GetNext(aPos);
               ircSock->Close();

              if(ircSock->Create(nextServer->GetRandomPort(), SOCK_STREAM, nextServer->GetServer()) == TRUE)
              {
                   success = true;
              }
         }
         if(!(aPos))
         {
              SetEvent(dPtr->m_hContinueClose);    
               return 0;
         }          

Good Luck
0
 

Author Comment

by:SGyves
ID: 9698953
what about Connecting rosh??? I see create but no connect.
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 9699071
Ohh yes, after the Create(0, then call Connect().Create will call Bind.
 Just a try out, not sure
0
 

Author Comment

by:SGyves
ID: 9819903
Sorry for the delay on the points Rosh.
0

Featured Post

ScreenConnect 6.0 Free Trial

Check out the updates in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI that improves session organization and overall user experience. See the enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question