Click to See Complete Forum and Search --> : CAsyncSocket::Connect() keeps returning WSAENOTSOCK The descriptor is not a socket.


testacc1234
February 14th, 2008, 02:27 PM
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.

Richard.J
February 15th, 2008, 03:42 PM
try to bind the socket before the Connect(). Maybe that helps.

MikeAThon
February 15th, 2008, 07:22 PM
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
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.