Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

why m_pSocket.Create() return false?

Posted on 2003-12-08
6
Medium Priority
?
308 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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…
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.
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

719 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