Solved

why m_pSocket.Create() return false?

Posted on 2003-12-08
6
240 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
6 Comments
 
LVL 3

Accepted Solution

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

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

Author Comment

by:blindwolf
Comment Utility
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
Comment Utility
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Decoding 32 bit binary streams 6 30
Hibernate methods 2 58
has22 challenge 11 71
Fibonacci challenge 11 82
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

15 Experts available now in Live!

Get 1:1 Help Now