CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2008
    Posts
    1

    CAsyncSocket::Connect() keeps returning WSAENOTSOCK The descriptor is not a socket.

    Hi there,

    I'm trying to build a MFC-based Client app using the CAsyncSocket class and I keep receiving this error when I
    try to connect to the specified address and port. A portion of my code is provided below:

    if (!AfxSocketInit())
    //Display error
    else
    {
    CClientSocket* pSock = new CClientSocket;
    if (!pSock->Create())
    {
    //Display error
    delete pSock;
    }
    //Else created socket
    }

    ...
    int nError;
    const char *addr = "xxx.xxx.xxx.xxx";
    if (!CAsyncSocket::Connect(addr, 3490))
    {
    nError = CAsyncSocket::GetLastError();
    if (nError == WSAEWOULDBLOCK)
    //Asynchronous Attempt started
    else
    //Display error -THIS IS WHERE I GET TO!
    }

    This is where I keep receiving the (WSAENOTSOCK The descriptor is not a socket. - 10038) error. I have debugged it all the way to the point where ConnectHelper() is called and the returned m_hSocket handle is invalid. The SockAddr structures are getting filled correctly too. I really don't understand what I'm doing wrong. The included header file is <afxsock.h>. I know that the server is working because I have another test program (client) that uses the <winsock2.h> file, the server can communicate with the client. I really need some help. Thanks in advance.

  2. #2
    Join Date
    May 2001
    Location
    Germany
    Posts
    1,158

    Re: CAsyncSocket::Connect() keeps returning WSAENOTSOCK The descriptor is not a socket.

    try to bind the socket before the Connect(). Maybe that helps.

  3. #3
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: CAsyncSocket::Connect() keeps returning WSAENOTSOCK The descriptor is not a socket.

    Please post code that would compile. Yours obviously would not. For example, CAsyncSocket::Connect is a member function, not a static function, so this line of code makes no sense at all, and could notpossibly compile
    Code:
    if (!CAsyncSocket::Connect(addr, 3490))
    Please also use [ code ][ /code ] tags to format you code neatly.

    Mike

    PS: for a client, there is no need to call bind() explicitly. The call to connect() implicitly binds the socket.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured