Solved

CSocket Question

Posted on 2003-11-06
4
320 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
format the code in java 6 72
FizzBuzz challenge 9 73
Path of Workbook 3 45
Can not remove SSL certificate on iPhone 6 - iOS10.2 12 91
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…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

760 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now