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
Solved

why m_pSocket.Create() return false?

Posted on 2003-12-08
6
266 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
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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Add content to output file 4 67
ASCII Non-Printable characters/codes and their HTML equivalents 6 129
Detect CR LF to each line 12 169
scoreUp challenge 14 63
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
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.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

789 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