Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

why m_pSocket.Create() return false?

Posted on 2003-12-08
6
Medium Priority
?
322 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
  • 2
3 Comments
 
LVL 3

Accepted Solution

by:
freewell earned 200 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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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 a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

876 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