Solved

why m_pSocket.Create() return false?

Posted on 2003-12-08
6
276 Views
Last Modified: 2013-11-20
why my CSocket can't be created?
here after is my code:

CSocket m_pSocket;
if(!m_pSocket.Create()){
     return -1;
}

It return at line 3! what's wrong?
I have used it well before, but currently not.

somebody teach me pls.
0
Comment
Question by:blindwolf
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
freewell earned 50 total points
ID: 9902129
Call the AfxSocketInit() in your Application's InitInstance()

if (!AfxSocketInit())
{
    AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
    return FALSE;
}
0
 

Author Comment

by:blindwolf
ID: 9902219
Thank you freewell,

That's works!
but,  when I connet to the server, which run in localhost,  it return false either. here after is my code.


int nRet;
           CSocket m_pSocket;
           if (!AfxSocketInit()){
               AfxMessageBox(IDP_SOCKETS_INIT_FAILED);
               return false;
           }
      
           if(!m_pSocket.Create()){
      AfxMessageBox("create fail");
      return FALSE;      
           }
           if(!m_pSocket.Connect(m_hostIP, m_port)){
            nRet=WSAGetLastError();
            return false;      //it returns,  nRet=10061
           }

is it because the server, which are not providing porper listening socket?
0
 
LVL 3

Expert Comment

by:freewell
ID: 9902257
10061 WSAECONNREFUSED : No connection could be made because the target machine actively refused it.

Check your m_port value, which determines which server application you are connecting to.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

762 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